Skip to main content
Known Participant
April 17, 2013
Answered

Rotating vector

  • April 17, 2013
  • 1 reply
  • 1680 views

Hi guys!

Well, my problem is not really program-related, it's more math related (math was never my strong side) and I thought maybe someone here could help me out...

Lets says I have 2 points in the X-Y plane: A(180,180) , B(310,310), now I craete a vector from B to A: V=(-180 , -180).

Now, I need to rotate that vector around point B at 1 degree intervals (in an OnEnterFrame event).

I cant seem to figure out the math required...can someone please help me out?

Thank you!

This topic has been closed for replies.
Correct answer kglad

A defines the location of a blitted object which is on stage (though I don't see how it matters).

Its not a problem of displaying them on the stage, it's a pure math problem; Consider A and B to be invisible points in the plane, and A need to circle B in a fixed radius.

It really is't even complex math, I'm missing something I can't seem to find what :/


use:

var A:Point = new Point(180,180);

var B:Point = new Point(310,310);

var angle:Number = Math.atan2(-130,-130);

var L:Number = Math.sqrt(130*130*2);

var nextX:Number = B.x+L*Math.cos(angle);

var nextY:Number = B.y+L*Math.sin(angle);

this.addEventListener(Event.ENTER_FRAME,f);

function f(e:Event):void {

    angle+=Math.PI/180;

    nextX = B.x+L*Math.cos(angle);

    nextY = B.y+L*Math.sin(angle);

}

1 reply

kglad
Community Expert
Community Expert
April 17, 2013

what is your vector?  is it a movieclip?  is it a line drawn dynamically (using the graphics class)?  something else?

Sason922Author
Known Participant
April 17, 2013

The vector exsits only in the code, its a simple subtraction of 2 points, as detailed above.

point B is fixed, at the tip of point A there is an object (but is a child of the stage, the points exists only in the code, they are not objects), I need to update to location of point A and as a result to move the object.

Sason922Author
Known Participant
April 17, 2013

I need to achieve something resembels a clock - move A around B in a fixed radius circle