I'm trying to find the centroid of each slice in a pie chart. Assuming the center of the circle is the origin, how do I calculate the x and y coordinates of the centroid of each slice?
I have the radius, start angle, and end angle of each slice.
I know how to calculate the centroid of a slice when that slice's starting angle is 0; that's answered here. But this assumes you have the angle alpha of the slice, starting at 0 (which JavaScript assumes is the place normally thought of as pi/2). I want the coordinates of, for example, the centroid of the red slice in this photo:
.
Let's say the angle alpha of the red slice is 1 radian (for simplicity, startAngle = 6 and endAngle = 5, this isn't exact but close to the actual angles in the photo) and the radius of the chart is 400px. Using the formula, xbar = (2/3)(r/a)sin(a) = (2/3)(400/1)(.84147) = 224.39226px which would be ~225px to the right of the origin, nowhere near the actual x coordinate of the centroid because the formula assumes the start angle of the slice is 0.
Also, the starting point being the coordinates of pi/2 and not 0 may contribute to the problem? I'm not sure.
How do I find the actual x coordinate of the centroid?