Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
5 registered members (alibaba, 7th_zorro, AndrewAMD, 2 invisible), 1,030 guests, and 0 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
sin, cos, tan calculations incorrect? #225975
09/06/08 23:49
09/06/08 23:49
Joined: Apr 2004
Posts: 516
USA
Trooper119 Offline OP
User
Trooper119  Offline OP
User

Joined: Apr 2004
Posts: 516
USA
This might currently be known, perhaps not, but I have a strange issue I'd like to run past you guys before I submit this in the bug section. Why is it if I have the following code:
Code:
fcos(90, 1);
fsin(90, 1);
ftan(90, 1);
cos(90);
sin(90);
tan(90);

Keep in mind according to the manuel all fsin, fcos, and ftan do is do something similar to the following. (But does it more accurately in some way)
Code:
fcos(x, y)
{
   y*cos(x);
}

Now anyone who knows the properties of sin, cos, and tangent knows that my code at the top should return the results
fcos(90, 1); = 0
fsin(90, 1); = 1
ftan(90, 1); = Infinity
cos(90); = 0
sin(90); = 1
tan(90); = Infinity

However when looking at the results in game they actually give
fcos(90, 1) = 0 //Correct
fsin(90, 1) = 1 //Correct
ftan(90, 1) = 2097152 //Close enough, we can ignore it doesn't give an error, actually we prefer this
cos(90) = -0.448 //Say what?
sin(90) = 0.894 //Now I'm confused
tan(90) = -1.995 //Where do these come from?

Also looking at the acos, asin, and atan give strange numbers as well where the facos, fasin, and fatan give more expected results.

Upon doing all of this I realized one thing, are these their Radian answers for whatever reason? Anyway I'm confused on the results, and with the help of fcos, fsin and ftan I can get the answer I want, but I would like a solution to this issue if anyone knows it.


A clever person solves a problem.
A wise person avoids it.
--Einstein

Currently Codeing: Free Lite-C
Re: sin, cos, tan calculations incorrect? [Re: Trooper119] #225981
09/07/08 00:11
09/07/08 00:11
Joined: Mar 2006
Posts: 3,538
WA, Australia
J
JibbSmart Offline
Expert
JibbSmart  Offline
Expert
J

Joined: Mar 2006
Posts: 3,538
WA, Australia
yes, they're in radians. they are either float or double trigonometric functions, and when you stick a constant in there, a7 assumes you are calling the float/double version. if you used vars you'd get the var version, which uses degrees. or, if you want to make sure it uses degrees call sinv, cosv, tanv, asinv, acosv, atanv.

i think it's because radians are the standard unit of measure for angles, so conitec wanted to move to using those without losing backwards compatibility with those using degrees.

julz

Last edited by JulzMighty; 09/07/08 00:12. Reason: typo

Formerly known as JulzMighty.
I made KarBOOM!
Re: sin, cos, tan calculations incorrect? [Re: JibbSmart] #225985
09/07/08 00:46
09/07/08 00:46
Joined: Apr 2004
Posts: 516
USA
Trooper119 Offline OP
User
Trooper119  Offline OP
User

Joined: Apr 2004
Posts: 516
USA
I appreciate it does seem strange that sin, cos and tan all use radians while fsin, fcos, and ftan all use degrees. I guess technically it isn't a bug according to what you said, it is strange to say the least though.

Thanks for the response.


A clever person solves a problem.
A wise person avoids it.
--Einstein

Currently Codeing: Free Lite-C
Re: sin, cos, tan calculations incorrect? [Re: Trooper119] #226016
09/07/08 11:05
09/07/08 11:05
Joined: Aug 2000
Posts: 1,140
Baunatal, Germany
Tobias Offline

Moderator
Tobias  Offline

Moderator

Joined: Aug 2000
Posts: 1,140
Baunatal, Germany
The reason is that in standard C, sin and cos are using radians. But var variables are using degrees.


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1