Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 5288

SDK • Re: Lua math issue

$
0
0
To put slimhazard's comments into visual form ...

Code:

  _|_                             ___ | | |__                       __| : |   |    |                     |    :   |    |_                   _|    :   |      |                 |      :   |-------|---------------|---------   |       :|_           _|:       :   |       :  |         |  :       :   |       :  |__     __|  :       :   |       :     |___|     :       :   |       :       :       :       :           0       90     180     270     360Degrees          0     1.5708 3.14159 4.71239 6.28319Radians (approx)
So what 'cos(rad(90))' gives depends on which side of 'cos(π/2)' it falls. If to the left you get a small positive number, to the right a small negative number. Just as you are seeing. The result you get isn't badly wrong, just slightly negative when you weren't expecting that.

If you want the cosine of a 90 degree angle to always deliver an exact zero I would suggest you need to avoid radians. Or apply some 'fudge factor'.

Statistics: Posted by hippy — Mon Jul 22, 2024 12:32 pm



Viewing all articles
Browse latest Browse all 5288

Trending Articles