Ladies and gentlemen. When you pass a parameter to Math.sin() or the Math.cos() function, the language assumes that you are using Radians, not degrees. As you saw, there was no discernible pattern, so unless you had started with three there was no way for you to figure out why it didn't work right. What is a Radian? Well, assuming that there are to rays pointing out from the center of a circle, making an angle P at the center, and assuming that the length of the arc facing angle P is equal to the radius of the circle, one radian is equal to the measure of angle P.
About how many degrees is that? 57.
What times 57 equals 180 degrees? Pi.
It takes some getting used to, but here's how it works. We know what it takes to get 180 degrees
(Pi x 1 radian), but we want to add one degree at a time, so (Pi x 1 radian) divided by 180 equals the amount we need to add every time we want to go one degree around the circle to place the next dot.
The following code is what we need:
cirqx = cirqx + (Math.cos(angle) *scaling);
cirqy = cirqy - (Math.sin(angle) *scaling);
angle += Math.PI/180;
No comments:
Post a Comment