
I'm a hero like Robert De Niro
Hey ppl,
I'm trying to calculate an angle and I'm stuck cuz I can't figure out how to inverse the sine result 0.841470984807897 to the find the angle.What's the syntax I'm missing here?
Thnx,
McMurphy

Hi..
To get the inverse Sine:
Maths.asin(number);
Good luck.
PS: I got this from elsewhere as I'm no maths genius. Thought you might enjoy the linkS
http://www.werehere.com/forum/Artic...ks/index.shtml
http://www.werehere.com/forum/Artic...01/index.shtml
[Edited by Marx on 02152001 at 07:11 AM]

angleInRadians = Math.asin(sineResult);
and 360 degrees = 2 * PI radians, so
angleInDegrees = Math.asin(sineResult) * (180 / Math.PI);
martin.

I'm a hero like Robert De Niro
Well... I thought that will be the line I'm looking for but now I have :
on (press) {
startDrag ("", true);
_root.x = 275;
_root.y = 200;
_root.start_rot = int(_root.ball._rotation);
}
on (release) {
stopDrag ();
_root.last_x = int(_root.ball._x);
_root.last_y = int(_root.ball._y);
_root.A = Math.abs(_root.last_x_root.x);
_root.B = Math.abs(_root.last_y_root.y);
_root.C = int(Math.sqrt((_root.A*_root.A)+(_root.B*_root.B)) );
angle = Math.sin(_root.B/_root.C);
angleInDegrees = Math.asin(angle) * (180 / Math.PI);
trace(angleInDegrees)
_root.new_rot = int(_root.ball._rotation);
}
and all I get in the output is: NAN NAN NAN NAN
Anyone can help?
[Edited by McMurphy on 02152001 at 09:56 AM]

what are you trying to do?

I'm a hero like Robert De Niro
I'm trying to create a dragable arrow that always point to the center of the movie.... I hate math but this is a whole lota fun
can you help?
McMurphy

ah...right...
so 275, 200 is the center of the movie?
you can set these variables in the first frame of the main timeline.
id call em :
centerX and centerY.
and then you wont need any code in the on(press) apart from the startDrag("",true) command.
oh..unless you want the arrow to be updated whilst its being dragged. If not then that should be fine.
the on release is a lot more simple than you would imagine.
Im assuming that the button is inside the movie clip being dragged (i spose it must be to do anything
when the mouse is released, you want to find the difference in x & y between the mc and the center of the movie.
I'll call them dx and dy.
dx = _root.centerX  this._x;
dy = _root.centerY  this._y;
now you need to find the angle (in degrees) that this point makes with the center. Fortunately theres a handy math function in flash, Math.atan2(y,x).
Just stick in the y and x values and it will give you the angle (in radians) :
angleInRadians = Math.atan2(dy,dx);
and convert it to degrees as before :
angleInDegrees = angleInRadians * (180 / Math.PI);
and just set the rotation to this angle.
this._rotation = angleInDegrees;
and that should be all thats needed.
try it out...
i hope it works for you.
martin.

I'd suggest you make a look up table once you get some values writen down so that your code runs faster, all those new nifty math actions are nice, but very slow compared to a lookup table

Originally posted by aubec
I'd suggest you make a look up table once you get some values writen down so that your code runs faster, all those new nifty math actions are nice, but very slow compared to a lookup table
You may be suprised but...the math object is faster. Indeed. I tested using the sine math object in a for loop that went 1000 times versus a look up table and the difference was a good 40ms or so...in favor of the math object. You can try your own testing if you want, but even if you do see a difference it will most likely be so small it will not even matter.
Anyway...I would like to see a script which used sine or cosine more than even a hundred times...

I'm a hero like Robert De Niro
Hey again ppl,
You've all been a gr8 help, especially theMartian but I'm afraid my success is far from being at hand.After reading theMartian explanation I finally got the arrow to rotate and lock its direction to the center of the movie but only in one quarter.
This is the result:
http://www.mcmurphy.co.il/stuff/ball.swf
I tried to place 4 if statements which add or subtract 90 to the degrees output according the arrow's position on the screen but it didn't help.
Any ideas?
McMurphy

I'm a hero like Robert De Niro
Well.. I got it working just gr8 and smooooooooth with ahab's help.Never thought of using atan or using any math object in Flash.Nice to see its not all that scary but boy, I hate my old math teacher in high school who didn't tell me I'll to know all that to use in Flash in the future.
http://www.mcmurphy.co.il/stuff/arrow.swf
McMurphy
Posting Permissions
 You may not post new threads
 You may not post replies
 You may not post attachments
 You may not edit your posts

Forum Rules

Click Here to Expand Forum to Full Width
