DisplayObject.rotation not matching trig functions
Posted
by futuraprime
on Stack Overflow
See other posts from Stack Overflow
or by futuraprime
Published on 2010-03-19T20:08:54Z
Indexed on
2010/03/19
20:11 UTC
Read the original article
Hit count: 367
I'm trying to label an animated pie chart, and I've been having a great deal of trouble getting rotated objects to line up with trigonometrically-positioned objects. So, for example, if I have a pie piece that's middle is angle theta and has been rotated n degrees in a tween, and then I try to position a label with code like this:
label.x = center.x + Math.cos((theta + n)/180 * Math.PI) * radius;
label.y = center.y + Math.sin((theta + n)/180 * Math.PI) * radius;
the label is often not aligned with the center of the pie slice. Since I am also zooming in to the pie chart a great deal, the error becomes significant enough that it occasionally causes the label to miss the pie slice altogether. The error seems relatively unpredictable, and it looks a great deal like a rounding error, but I don't see any obvious rounding going on (the trig functions evaluate to ten or so decimal places, which should be more than enough here).
How can I get these labels to position correctly?
© Stack Overflow or respective owner