A Flash Developer Resource Site

# Thread: [F8] Trig

1. ## [F8] Trig

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

2. Does it measure it in radians? If so how do you change it to degrees?

3. 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.

4. 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.

5. 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)```

6. 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?

7. 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.

8. 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);
```

9. 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.

10. ## Re:

Hey looky I've been banned for spamming

#### Posting Permissions

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

 » Home » Movies » Tutorials » Submissions » Board » Links » Reviews » Feedback » Gallery » Fonts » The Lounge » Sound Loops » Sound FX » About FK » Sitemap

Click Here to Expand Forum to Full Width