A Flash Developer Resource Site

1. ## [F8] Trig

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

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

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.  Reply With Quote

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:
```
return a * Math.PI / 180;
}

return a * 180 / Math.PI;
}
```

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

code:
```
```

Feel free to rename the functions to whatever you want.

Hope this helps.  Reply With Quote

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:
```
return a * Math.PI / 180;
}

return a * 180 / Math.PI;
}
```

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

code:
```
```

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)```  Reply With Quote

code:
```
Math.cos(this.dis2);
```

you would write

code:
```
```

As long as this.dis2 is measured in degrees, this should give you the required result. How is this.dis2 defined?  Reply With Quote

7. Originally Posted by dmonkey

code:
```
Math.cos(this.dis2);
```

you would write

code:
```
```

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.  Reply With Quote

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:
```
this.dis2 = this.dis2 * Math.PI / 180;

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

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:
```
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.  Reply With Quote

10. ## Re:

Hey looky I've been banned for spamming  Reply With Quote

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