Skip to content

Instantly share code, notes, and snippets.

@navono navono/pathSector.js
Last active Sep 13, 2018

Embed
What would you like to do?
使用坐标,获取扇形(Sector)的Path data(起始点、结束点、半径、开启角度、结束角度)
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
You can’t perform that action at this time.