Skip to content

Instantly share code, notes, and snippets.

@aleksandar-b
Created February 10, 2016 17:14
Show Gist options
  • Save aleksandar-b/3c79888361d2438e741c to your computer and use it in GitHub Desktop.
Save aleksandar-b/3c79888361d2438e741c to your computer and use it in GitHub Desktop.
getCirclePointAtLength() method for SVG circle element
function getCirclePointAtLength(element, point)
{
var element = document.querySelector(element);
var r = +element.getAttribute("r");
var x = +element.getAttribute("cx");
var y = +element.getAttribute("cy");
var Circumference = 2 * Math.PI *r;
var slice = 2 * Math.PI /Circumference;
var angle = slice * point;
var newX = x + r * Math.cos(angle);
var newY = y + r * Math.sin(angle);
return {x: newX, y: newY};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment