PDA

Click to See Complete Forum and Search --> : calculating next position within an orbit (f5)



kay_siegert
12-04-2002, 10:40 AM
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)!


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.

jonmack
12-04-2002, 12:13 PM
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.

kay_siegert
12-04-2002, 01:47 PM
thatīs it. thanks a lot.
k. ;)