I tried to do:
but i am getting 1-180 and 180 to 1 as i go around the pivoted point, instead of 1-360, what am i doing wrong??Code:Math.abs(Math.atan2((y1-y2),(x1-x2)))*(180/Math.PI)
Printable View
I tried to do:
but i am getting 1-180 and 180 to 1 as i go around the pivoted point, instead of 1-360, what am i doing wrong??Code:Math.abs(Math.atan2((y1-y2),(x1-x2)))*(180/Math.PI)
ok, i solved it myself!
Hi
I am facing the same problem.
Can you please help me , that how can i get the angle from 0-360 instead of 0-180.
my email is uzair@meragsm.com.
I am waiting for your reply.
Thanks
Hi,
You can easily fix this by doing the small changes. This one really help
var angle=Math.atan2((y1-y2),(x1-x2))
if (angle<0) {
angle +=3
}
angle=angle*(180/Math.PI)
It would be better if you made two other varibles:
dy=y2-y1
dx=x2-x1
Your y's and x's are backwards. also. instead of having to do the 180/Math.PI you could use:
object.rotation= ATAN2(x,y)
this returns in degrees.
I will give you a free script that I used to make an Ipod dial:
var dial=element ("dial2");
var windowScroller=element ("window scroller");
stage.addEventListener(Event.ENTER_FRAME,rot)
function rot(evt:Event):void
{
var mx=(mouseX-dial.x);
var my=(mouseY-dial.y);
dial.rotation= ATAN2(mx,-my)
var y0= 5
var y1= dial.rotation/1.4
for(var i:Number = 0;i<=130;i++)
{
windowScroller.y= y1;
}
}
This makes a dial rotate to the position of the mouse (face it). It also makes the windowScroller change y position as you rotate the mouse around.
Suthers,
Welcome to flashkit, I see you've found all the old threads.
If you look at Adobe's documentation, the parameters for atan2 are actually (y,x).
http://livedocs.adobe.com/flash/9.0/main/00001821.html
It's supposed to look similar to the way they teach you to find the angle of vector <x,y> in math class:
atan(y/x) -- what normal people use
atan2(y,x) -- what programmers use