PDA

Click to See Complete Forum and Search --> : problems with sin and cos



Sekots
04-04-2002, 01:50 PM
I cant get the sin cos to work in flash 5.
I write it like this
SinValue=Math.sin(angle);
CosValue=Math.cos(angle);
but its always different then what a calculator reads out to. Please help me...

minger
04-04-2002, 02:14 PM
I may be wrong, but I think that Flash works in radians. If you just plug something into your calculator without first changing it, it is reading in degrees. For example:
sin(30 degrees) = 1/2 (i think) while
sin(pi/6 rads) = 1/2
the conversion isn't that difficult.

radians = degrees*pi/180

so 45 degrees = pi/4
Should you need to convert rads back to degrees, just solve for degrees, it's not hard. If Flash does use degrees, then hey, at least you learned something new, right? Now you can brag to your friends that you know how to convert degrees to radians. Impress them. :)

Sekots
04-04-2002, 03:11 PM
That worked! Thanks for your help Minger, thats been bugging me for the last couple days.

bit-101
04-04-2002, 03:46 PM
here is something to tattoo to the back of your hand...or at least memorize:

degrees=radians*180/Math.PI
radians=degrees*Math.PI/180

you always need to use radians in flash's trig functions, but degrees for _rotation. a bit of a pain, but that's what we have.

TSO
04-08-2002, 08:36 AM
here is something to tattoo to the back of your hand...or at least memorize:
degrees=radians*180/Math.PI
radians=degrees*Math.PI/180


Huh! I didnīt notice that flash wants Math.cos(x) -> x value in radians too, I thought I was going totally insane! ;)

slight
04-08-2002, 09:24 PM
Which begs the question, can you define constants in Flash and if so, how?
I was pleasantly surprised that it swallows this without error:

Math.RAD2DEG = 57.29578;
Math.DEG2RAD = 0.01745329;

Is there a 'proper' way?

bit-101
04-08-2002, 09:54 PM
that's about as proper as it gets. Math is an object. you are assigning a property to an object. constants are usually in all caps.
you could get a little more accurate and say:

Math.RAD2DEG=180/Math.PI;
Math.DEG2RAD=Math.PI/180;