Skip to content

Instantly share code, notes, and snippets.

@ffantasy
Created March 4, 2020 06:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ffantasy/c37e1e9cbdeaa4ed920f47d1ca2d7932 to your computer and use it in GitHub Desktop.
Save ffantasy/c37e1e9cbdeaa4ed920f47d1ca2d7932 to your computer and use it in GitHub Desktop.
function polarToCartesian(centerX, centerY, radius, angleInDegrees) {
var angleInRadians = (angleInDegrees-90) * Math.PI / 180.0;
return {
x: centerX + (radius * Math.cos(angleInRadians)),
y: centerY + (radius * Math.sin(angleInRadians))
};
}
function getArcPath(centerX, centerY, radius, startAngle, endAngle){
var start = polarToCartesian(centerX, centerY, radius, endAngle);
var end = polarToCartesian(centerX, centerY, radius, startAngle);
var largeArcFlag = endAngle - startAngle <= 180 ? "0" : "1";
var d = [
"M", start.x, start.y,
"A", radius, radius, 0, largeArcFlag, 0, end.x, end.y
].join(" ");
return d;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment