Created
February 10, 2016 17:14
-
-
Save aleksandar-b/3c79888361d2438e741c to your computer and use it in GitHub Desktop.
getCirclePointAtLength() method for SVG circle element
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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