Last active
September 13, 2018 23:48
-
-
Save navono/c47ec8a6c87d16f7c73b52fdfe8f8602 to your computer and use it in GitHub Desktop.
使用坐标,获取扇形(Sector)的Path data(起始点、结束点、半径、开启角度、结束角度)
This file contains 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 describeArc(x, y, radius, startAngle, endAngle) { | |
var start = polarToCartesian(x, y, radius, endAngle); | |
var end = polarToCartesian(x, y, radius, startAngle); | |
console.log('start: ', start); | |
console.log('end: ', end); | |
var largeArcFlag = Math.abs(endAngle - startAngle) <= 180 ? "0" : "1"; | |
const clockwise = endAngle < 0 ? 1 : 0; | |
var d = [ | |
"M", start.x, start.y, | |
"A", radius, radius, 0, largeArcFlag, clockwise, end.x, end.y, | |
"L", x, y, | |
"Z" | |
].join(" "); | |
return d; | |
} | |
function degree2Radian(degrees) { | |
// return degrees * Math.PI / 180; | |
return (degrees - 90) * Math.PI / 180; | |
} | |
function radian2Degree(radians) { | |
return radians * 180 / Math.PI; | |
} | |
function polarToCartesian(centerX, centerY, radius, angleInDegrees) { | |
const angleInRadians = degree2Radian(angleInDegrees); | |
return { | |
x: centerX + (radius * Math.cos(angleInRadians)), | |
y: centerY + (radius * Math.sin(angleInRadians)) | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment