calculating next position within an orbit (f5)
A Flash Developer Resource Site

Thread: calculating next position within an orbit (f5)

1. calculating next position within an orbit (f5)

i can´t figure out whats wrong
i´m trying to rotate an object about the origin(x=0, y=0).

to manage that i first tried to calculate the next x and the y coordinate for my object to move to.
NOTE: it´s only for one quadrant (where x and y are positive)!
Code:
```onClipEvent(load){
// init
movingDegree=2;
_x=50;
_y=100;
}
onClipEvent(enterFrame){
// calculating radius and angle referring to my origin
a = Number(_x);
b = Number(_y);
r = Math.sqrt((a*a)+(b*b));
Angle = Math.atan(b/a)*180/Math.PI;
// works great so far

// now i´m increasing the angle (2 degrees)
// ... and calculate adjacent leg (nextX) and the opposite leg(nextY) that are the coordinates of my next point at the same time

nextAngle = Number(Angle+movingDegree);
nextX=Number(Math.cos(nextAngle)*r);
nextY=Number(Math.sin(nextAngle)*r);
}```
i get a completely different result when i calculate it with my pocket calculator.
i don´t get it.
the file is attached.
thankful for any help,
k.

2. At the end, where you work out nextX and nextY you are putting an angle in degrees into the cos() and sin() functions. The parameter needs to be in radians *(Pi/180) - that will work.

3. that´s it. thanks a lot.
k.

Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

 » Home » Movies » Tutorials » Submissions » Board » Links » Reviews » Feedback » Gallery » Fonts » The Lounge » Sound Loops » Sound FX » About FK » Sitemap