A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: problems with sin and cos

  1. #1
    Junior Member
    Join Date
    Nov 2001
    Posts
    2
    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...

  2. #2
    Senior Member
    Join Date
    Mar 2002
    Posts
    183
    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.

  3. #3
    Junior Member
    Join Date
    Nov 2001
    Posts
    2
    That worked! Thanks for your help Minger, thats been bugging me for the last couple days.

  4. #4
    Senior Member
    Join Date
    Jan 2002
    Posts
    368
    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.


  5. #5
    Member
    Join Date
    Mar 2001
    Posts
    70
    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!

  6. #6
    Junior Senior
    Join Date
    Nov 2000
    Location
    sydney
    Posts
    565
    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?

  7. #7
    Senior Member
    Join Date
    Jan 2002
    Posts
    368
    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;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center