Hi,
I have this code for rotating a point in 2D around a central axis of (0.0, 0.0)…
local xx = x*math.cos(theta) - y*math.sin(theta)
local yy = x*math.sin(theta) + y*math.cos(theta)
Here, the ‘theta’ value is the amount to rotate in radians.
I converted this from my test program, written in C-sharp. It is exactly the same code - except for where I can only assume lua is using double point values as it is an untyped language.
The problem is that the above code does not produce the correct rotation, whereas the C-sharp code does. For example, rotating a (10.0, 10.0) point by 90 degrees would involve a very small radian (I won’t calculate it right now) and produce (-10.0, 10.0) - essentially flipping the point across the Y axis. This code does not.
What am I missing about lua that perhaps other are taking for granted? I am very new to this and only came to the language because of Corona, specifically for game programming. Is there something not obvious about the handling of floating point or double precision numbers?
Thanks,
Matt. [import]uid: 8271 topic_id: 1753 reply_id: 301753[/import]