Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hello everyone

how actually math.sin() works in as3??
i'm confuse with the result i got

i try to trace(math.sin( 180 ))

in reality i should be 0,
but i got -0.8011526357338304

and i also try trace(math.sin(90))
it should be 1
but i got 0.8939966636005579

and some of the value was negative ( as what i understand about calcuation of sine , value in between 0 - 179 should be postive )

can someone pls correct my mistake ?

What I have tried:

i have try this code

trace(math.sin(180))
result was -0.8011526357338304

and other value was incorrect besides math.sin(0)
Posted

1 solution

You get such a result because the sin method argument is supposed to be given in radians[^] while you are using degrees.
Try, for instance
as
trace( Math.sin( degrees * Math.PI / 180 ))


See: "Math - Adobe ActionScript 3(AS3) API Reference"[^].
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 5-Feb-16 14:41pm    
My 5. It's amazing that the inquirer assumed degrees without even a doubt.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900