A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: [F8] Trig

  1. #1
    Registered N00b
    Join Date
    Jan 2005
    Location
    i'm a noob
    Posts
    208

    [F8] Trig

    Why does my program think
    Code:
    Math.sin(45)
    equal 0.850903524534118?
    I want it to equal one like it should.
    ^ noob

  2. #2
    Registered N00b
    Join Date
    Jan 2005
    Location
    i'm a noob
    Posts
    208
    Does it measure it in radians? If so how do you change it to degrees?
    ^ noob

  3. #3
    Registered N00b
    Join Date
    Jan 2005
    Location
    i'm a noob
    Posts
    208
    This is the code that I am using:
    Code:
    this.exdisx = (Math.cos(this.dis2) * this.disc2)
    this.exdisy = (Math.sin(this.dis2) * this.disc2)
    this.dis2 is the angle of the triangle, and disc2 is the hypotenuse. But it doesn't work. I'm using these points as x and y cordinates of an MC and all it does is go in seemingly random places when I change dis2 and disc.
    ^ noob

  4. #4
    All 1s and 0s dmonkey's Avatar
    Join Date
    Nov 2005
    Location
    Leeds, UK
    Posts
    606
    Hi,

    Yes, Flash uses radians when calculating angles, but degrees when rotating objects (go figure). Use these handy functions to convert from deg to rad (and vice versa):

    code:

    function degToRad(a:Number):Number {
    return a * Math.PI / 180;
    }

    function radToDeg(a:Number):Number {
    return a * 180 / Math.PI;
    }



    Incidentally, sin(45) is actually 1 / sqrt(2), or 0.707106781186547:

    code:

    trace( Math.sin(degToRad(45)) );



    Feel free to rename the functions to whatever you want.

    Hope this helps.
    "If I have seen further, it is by standing on the shoulders of giants." - Sir Isaac Newton

  5. #5
    Registered N00b
    Join Date
    Jan 2005
    Location
    i'm a noob
    Posts
    208
    Quote Originally Posted by dmonkey
    Hi,

    Yes, Flash uses radians when calculating angles, but degrees when rotating objects (go figure). Use these handy functions to convert from deg to rad (and vice versa):

    code:

    function degToRad(a:Number):Number {
    return a * Math.PI / 180;
    }

    function radToDeg(a:Number):Number {
    return a * 180 / Math.PI;
    }



    Incidentally, sin(45) is actually 1 / sqrt(2), or 0.707106781186547:

    code:

    trace( Math.sin(degToRad(45)) );



    Feel free to rename the functions to whatever you want.

    Hope this helps.
    So how do I put your code into this code:
    Code:
    this.exdisx = (Math.cos(this.dis2) * this.disc2)
    this.exdisy = (Math.sin(this.dis2) * this.disc2)
    ^ noob

  6. #6
    All 1s and 0s dmonkey's Avatar
    Join Date
    Nov 2005
    Location
    Leeds, UK
    Posts
    606
    Well instead of

    code:

    Math.cos(this.dis2);



    you would write

    code:

    Math.cos( degToRad(this.dis2) );



    As long as this.dis2 is measured in degrees, this should give you the required result. How is this.dis2 defined?
    "If I have seen further, it is by standing on the shoulders of giants." - Sir Isaac Newton

  7. #7
    Registered N00b
    Join Date
    Jan 2005
    Location
    i'm a noob
    Posts
    208
    Quote Originally Posted by dmonkey
    Well instead of

    code:

    Math.cos(this.dis2);



    you would write

    code:

    Math.cos( degToRad(this.dis2) );



    As long as this.dis2 is measured in degrees, this should give you the required result. How is this.dis2 defined?
    this.dis2 is a angle measured in degrees from 1 to 45, in a right triangle. "this.disc" is the hyposetunse of this right triangle. I want the sine and cosine of this angle displayed in degrees so I can use it to find the lengths of the legs of the right triangle. I don't really care about radiens, I don't know what they do. And I don't have much experience with the fuction command. I've only used it in one situation.
    ^ noob

  8. #8
    All 1s and 0s dmonkey's Avatar
    Join Date
    Nov 2005
    Location
    Leeds, UK
    Posts
    606
    Hi,

    I'm afraid you have to use radians. All I'm doing is doing a conversion from degrees to radians in the code. If you don't want to use a function, then just do the following:

    code:

    //Convert from degrees to radians
    this.dis2 = this.dis2 * Math.PI / 180;

    //Calculate
    this.exdisx = (Math.cos(this.dis2) * this.disc2);
    this.exdisy = (Math.sin(this.dis2) * this.disc2);

    "If I have seen further, it is by standing on the shoulders of giants." - Sir Isaac Newton

  9. #9
    Registered N00b
    Join Date
    Jan 2005
    Location
    i'm a noob
    Posts
    208
    Quote Originally Posted by dmonkey
    Hi,

    I'm afraid you have to use radians. All I'm doing is doing a conversion from degrees to radians in the code. If you don't want to use a function, then just do the following:

    code:

    //Convert from degrees to radians
    this.dis2 = this.dis2 * Math.PI / 180;

    //Calculate
    this.exdisx = (Math.cos(this.dis2) * this.disc2);
    this.exdisy = (Math.sin(this.dis2) * this.disc2);

    Thank you so much. I was trying to convert the final product into radiens after I had already sine'd it. I didn't know I was suppose to convert it before, thx.
    ^ noob

  10. #10
    Banned
    Join Date
    Dec 2006
    Posts
    18

    Re:

    Hey looky I've been banned for spamming
    Last edited by Frets; 12-30-2006 at 02:24 AM. Reason: spam

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