Copy link to clipboard
Copied
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!
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);
}
Copy link to clipboard
Copied
what is your vector? is it a movieclip? is it a line drawn dynamically (using the graphics class)? something else?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
I need to achieve something resembels a clock - move A around B in a fixed radius circle
Copy link to clipboard
Copied
create an movieclip (like the minute hand of a clock) pointing to the right (0degrees) with registration point at its left middle and instance name arrow_mc:
you can then use:
arrow_mc.x=310;
arrow_mc.y=310;
arrow_mc.rotation=180*Math.atan2(-130,-130)/Math.PI;
arrow_mc.addEventListener(Event.ENTER_FRAME,rotateF);
function rotateF(e:Event):void{
arrow_mc.rotation++;
}
Copy link to clipboard
Copied
Thanks kglad, but thats not really what I'm looking for, I know how to rotate a movie clip, that's not the case here (can't use rotation)
the only thing I need to do is to updtae to location of A, and I need to do it by updating it's x and y cords.
This is the code I'm currently using, maybe you can tell me what I'm doiing wrong:
first I define UnitVecX UnitVecY and VecNormal outside the Event:
UnitVecX = A.x - B.x
UnitVecY = A.y - B.y
VecNormal = Math.sqrt(UnitVecX * UnitVecX + UnitVecY * UnitVecY );
in the Event itself:
angle = Math.atan2(UnitVecY , UnitVecX )*180/Math.PI +90;
angle = angle +1;
nextX = A.x + UnitVecX * VecNormal * Math.cos(angle * Math.PI/180);
nextY = A.y + UnitVecY * VecNormal * Math.sin(angle * Math.PI/180);
UnitVecX = (nextX - B.x) / VecNormal;
UnitVecY = (nextY - B.y) / VecNormal
finally (also in the event)
A.x = nextX ;
A.y = nextY;
Copy link to clipboard
Copied
what kind of objects are A and B?
what's the displayobject that looks like a vector or arrow?
Copy link to clipboard
Copied
A and B are basicly points: A(x,y) B(x,y) (they actually define proprties of a custome class in my project).
Think of them as just points in the plane...(there isnt really any arrow....)
Copy link to clipboard
Copied
they are either points (in flash actionscript) or they are not. if they are, that's fine but, they are not displayobjects. if they are not points, are they objects?
in either case, you don't appear to have any displayobject so nothing will be seen on stage. is that what you want?
Copy link to clipboard
Copied
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 😕
Copy link to clipboard
Copied
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);
}
Copy link to clipboard
Copied
Yay it works!
Thank you very much!!!
Copy link to clipboard
Copied
you're welcome.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now