Trigonometry
by Jeremy Tilton · in Torque Game Builder · 03/25/2005 (9:26 pm) · 10 replies
Need some Sine/Cosine Functions.
Found that mcos(90) returns .4somethingsomething
From what I can tell, this is the answer for 90 radians. Damn my luck, I thought I'd never have to deal with those things after graduating college. My nightmares are coming back! Stupid radians! I think I saw a thread a couple weeks ago about T2D using angles and all that, never thought I'd have to care.... Ok, so here's my questions:
1. Someone confirm that mcos()/msin() require radians instead of degrees.
2. Are there functions that use degrees instead?
3. Is there a PI constant in torquescript if I really have to convert?
4. What is it?
Found that mcos(90) returns .4somethingsomething
From what I can tell, this is the answer for 90 radians. Damn my luck, I thought I'd never have to deal with those things after graduating college. My nightmares are coming back! Stupid radians! I think I saw a thread a couple weeks ago about T2D using angles and all that, never thought I'd have to care....
1. Someone confirm that mcos()/msin() require radians instead of degrees.
2. Are there functions that use degrees instead?
3. Is there a PI constant in torquescript if I really have to convert?
4. What is it?
About the author
#2
2. No
3. I don't think so, but you can use mDegToRad() and mRadToDeg() to avoid most of the wayward pastry.
Bit of a sticking point: T2D treats 0 degrees as pointing down the negative y axis while the Torque math functions treat 0 degrees as pointing along positive x. Also, positive angles are clockwise in the T2D system and counterclockwise in standard Torque.
I ended up just wrapping the Torque math functions in a package to handle the translation and forgot about the differences:
03/25/2005 (9:53 pm)
1. Yes2. No
3. I don't think so, but you can use mDegToRad() and mRadToDeg() to avoid most of the wayward pastry.
Bit of a sticking point: T2D treats 0 degrees as pointing down the negative y axis while the Torque math functions treat 0 degrees as pointing along positive x. Also, positive angles are clockwise in the T2D system and counterclockwise in standard Torque.
I ended up just wrapping the Torque math functions in a package to handle the translation and forgot about the differences:
package MathHelper
{
function mDegToRad( %angle )
{
return Parent::mDegToRad( 90 - %angle );
}
function mRadToDeg( %rad )
{
return 90 - Parent::mRadToDeg(%rad);
}
function mCos( %angle )
{
return Parent::mCos( mDegToRad(%angle) );
}
function mSin( %angle )
{
return Parent::mSin( mDegToRad(%angle) );
}
function mTan( %angle )
{
return Parent::mTan( mDegToRad(%angle) );
}
function mACos( %cos )
{
return mRadToDeg( Parent::mACos(%cos) );
}
function mASin( %sin )
{
return mRadToDeg( Parent::mASin(%sin) );
}
function mATan( %tan )
{
return mRadToDeg( Parent::mATan(%tan) );
}
};
ActivatePackage(MathHelper);(Hopefully) never worry about radians/differences between Torque/T2D math again.
#3
There is nothing clockwise about basic trigonometry functions such as mCos/mSin, it's how you apply them that gives you specific characteristics such as you mention.
You can use...
These are primitive functions, nothing in them really defines angles as "up" or "clockwise".
Just thought I'd point this out.
- Melv.
03/26/2005 (3:20 am)
Quote:T2D treats 0 degrees as pointing down the negative y axis while the Torque math functions treat 0 degrees as pointing along positive x. Also, positive angles are clockwise in the T2D system and counterclockwise in standard Torque.
There is nothing clockwise about basic trigonometry functions such as mCos/mSin, it's how you apply them that gives you specific characteristics such as you mention.
You can use...
%dir = mRadToDeg(mAtan( %newX - %oldX, %oldY - %newY ) );... or instead of using...
%x = cos(%theta) %y = -sin(%theta)... you can use...
%x = sin(%theta) %y = -cos(%theta)
These are primitive functions, nothing in them really defines angles as "up" or "clockwise".
Just thought I'd point this out.
- Melv.
#5
One radian is the angle at the center of a circle, where the length of the arc equals the radius. Think about it for a second.
2 pi r is the circumference of a circle, rememeber? So actually, if you draw yourself a little picture, there are two pi radians in 360 degrees.
Overall, radians are much simpler to work with, but since they're not the units you're taught first in school, most people don't like 'em.
Gary (-;
03/26/2005 (8:55 am)
Actually, radians are a lot more intuitive and simpler to work with than degrees.One radian is the angle at the center of a circle, where the length of the arc equals the radius. Think about it for a second.
2 pi r is the circumference of a circle, rememeber? So actually, if you draw yourself a little picture, there are two pi radians in 360 degrees.
Overall, radians are much simpler to work with, but since they're not the units you're taught first in school, most people don't like 'em.
Gary (-;
#6
With regards to where 0 is and where clockwise is etc etc. Melv is right, it didn't matter. I just didn't take my Trig for granted when I wanted to figure out how to find my X,Ys. It really just amounts to a phase shift. So instead of my X equaling cos(theta)*r, it is sin(theta)*r, and vice versa.
03/26/2005 (9:25 am)
Gary is right, it'd be like America switching to the Metric System. Metric system has its conveniences, but because we were taught American Standard, metric seems so much harder. With regards to where 0 is and where clockwise is etc etc. Melv is right, it didn't matter. I just didn't take my Trig for granted when I wanted to figure out how to find my X,Ys. It really just amounts to a phase shift. So instead of my X equaling cos(theta)*r, it is sin(theta)*r, and vice versa.
#7
We're working on that. :)
- Melv.
03/26/2005 (10:26 am)
I think what we need at least here is documentation to clarify what takes what and what it returns.We're working on that. :)
- Melv.
#8
www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=5718
Console docs
03/26/2005 (11:49 am)
@Melvwww.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=5718
Console docs
#9
- Melv.
03/26/2005 (11:55 am)
I actually meant the fusion of the TGE + T2D stuff but yes, that does nicely for now. :)- Melv.
#10
But that link should help out people too
Hey King Bob, could you post this link on your FAQ?
03/26/2005 (12:02 pm)
That would be even better!!But that link should help out people too
Hey King Bob, could you post this link on your FAQ?
Torque Owner Chris Newman
2 functions that may help ya.
mRadToDeg()
mDegToRad()
These are console functions taken from TGE.