-
[F8] Trig
Why does my program think
equal 0.850903524534118?
I want it to equal one like it should.
-
Does it measure it in radians? If so how do you change it to degrees?
-
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.
-
All 1s and 0s
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
-
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)
-
All 1s and 0s
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
-
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.
-
All 1s and 0s
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
-
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.
-
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|