I am trying to understand the math in this demo version of raphael.js:
http://raphaeljs.com/pie.js
Calculate the sector method:
function sector(cx, cy, r, startAngle, endAngle, params) {
var x1 = cx + r * Math.cos(-startAngle * rad),
x2 = cx + r * Math.cos(-endAngle * rad),
y1 = cy + r * Math.sin(-startAngle * rad),
y2 = cy + r * Math.sin(-endAngle * rad);
return paper.path(["M", cx, cy, "L", x1, y1, "A", r, r, 0, +(endAngle - startAngle > 180), 0, x2, y2, "z"]).attr(params);
}
This is the actual demo:
http://raphaeljs.com/pie.html
My math is a little rusty, and I am trying to understand the function of the sector - given the startAngle and endAngle parameters (each value of the start and end point from 0 to 360, constituting an arc), why does this function work?