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

Results 1 to 3 of 3

Thread: calculating next position within an orbit (f5)

  1. #1
    Senior Member
    Join Date
    Apr 2001
    Location
    Candyland
    Posts
    423

    calculating next position within an orbit (f5)

    i cant figure out whats wrong
    im 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: its 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 im 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 dont get it.
    the file is attached.
    thankful for any help,
    k.
    Attached Files Attached Files

  2. #2
    avatar free
    Join Date
    Jul 2002
    Location
    UK
    Posts
    835
    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.
    jonmack
    flash racer blog - advanced arcade racer development blog

  3. #3
    Senior Member
    Join Date
    Apr 2001
    Location
    Candyland
    Posts
    423
    thats 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
  •  




Click Here to Expand Forum to Full Width


HTML5 Development Center

Poll by Flashkit.com