|
Cosd
Jul 31, 2004 5:55:01 GMT -5
Post by vertex on Jul 31, 2004 5:55:01 GMT -5
What do Cosd? I have understud it so, that Cosd the same is like Cos but work with degree and not like Cos width radian. But why this are display different values?:
Printr Cosd (90.0) Printr Cos((1.571)) To convert degree in radian you must say: rad = (Pi / 180)*degree 1.571 = (3.142 / 180.0)*90.0
And why is this value nagative?
Printr Atn (Tan (1.571)) cu olli
Edit: OK, Cosd has a bug on 90° and 270° all other values are correct (only little rounding bugs, but this is normal).
|
|
|
Cosd
Jul 31, 2004 6:40:00 GMT -5
Post by AHBanen on Jul 31, 2004 6:40:00 GMT -5
Olli, hyperphysics.phy-astr.gsu.edu/hbase/ttrig.html why some calculators and math librries give a seemingly incorrect result when using the arctangent function. (Also to complicate matters, because of rounding errors 90 degrees is not eactly 1.571 radians. ) André
|
|
|
Cosd
Jul 31, 2004 23:35:36 GMT -5
Post by Tom Mulgrew on Jul 31, 2004 23:35:36 GMT -5
cosd and sind are there because OpenGL stores angles in degrees, so I thought it useful to have some sin/cos/tan functions that didn't require you to convert your angles to radias all the time.
dim angle# angle# = 90 printr cosd (angle#) printr cos (angle# * m_pi / 180)
The cosd version is slightly more accurate, because Basic4GL uses 64 bit floating point arithmetic to convert the angle into radians. In the cos example, the conversion is done in the Basic4GL virtual machine which stores numbers in 32 bit floating point format, so the conversion is less precise. (I could build a 64bit version of Basic4GL, but it would run slower.)
I'm not sure why cosd(90) doesn't equal exactly 0, but I suspect rounding error. It is still less than 1/10000000000000000 out from the correct value. Seems about right for computer arithmetic.
-Tom
|
|
|
Cosd
Aug 1, 2004 7:46:26 GMT -5
Post by vertex on Aug 1, 2004 7:46:26 GMT -5
AHBanen: Oh, good. Now it's clear. Tom Mulgrew: Yes, CosD, SinD and TanD are very usefull. maybe you can write this:
void WrapCosD (TomVM& vm) { if (vm.GetRealParam (1) == 90 || vm.GetRealParam (1) == 270) vm.Reg ().RealVal () = 0.0; else vm.Reg ().RealVal () = cos (vm.GetRealParam (1) * M_DEG2RAD); }
|
|