angles and the great distortion


Ugh, today i found the great distortion between the physical math and the computer math. It is just the way they calculate radians and degrees.
By looking at the first graph you see that angles go anticlockwise in direction starting at 0 on right side. Great, this was teached in the primary school i think.
But then i run some LOVE2D test to see the difference. The angle 0 starts at left side but goes down so 90 degrees are south. 180 degrees are west. And 270 degrees are north when looking at the graph as if compass showing the angle direction.
So it goes clockwise. Not bad. But i got scrambled by the difference when calculating some nice bone like joint math for bridge and the chains going from castle towards the wooden ramp.
-- calculate point that starts at x1,y1 it's direction is angle in radians and goes in distance from x1,y1
function get_rotated_point(x1,y1,angle_rad,distance)
local x2 = x1 + math.cos(angle_rad)*distance
local y2 = y1 + math.sin(angle_rad)*distance
return x2,y2
end
-- calculate distance between points in 2D
function distance(x1,y1,x2,y2)
local dx = x2-x1
local dy = y2-y1
return math.sqrt(dx*dx+dy*dy)
end
-- calculate angle in radians between two points correctly in computer math scenario
function heading(x1,y1,x2,y2)
return math.atan2(y2-y1, x2-x1)
end
Alas, i needed to fix the code so the API knows how to use angles in degrees that i canvert to radians by angle_rad = math.rad(angle_deg) because the lua math understands only radians. Radians look like strange numbers with floating points 1.57… and they are long to remember. That is why i like the degrees approach where you know that 0 until 360 are integers and that i all that will make you happier. The code will look messy, but it will work better because angles in degrees you can prepare as constant table instead of calling math operations each time something needs to be recalculated.
With this few calculation i could really figure out the way angles work in love2D and propably in other engines that adapted this kind of rotation direction. Without this it would get messy each time i forget about the way it works.
LUA game developing for dumbies
Some nice ways of doing the lua game developing .
Status | In development |
Category | Other |
Author | Bastian |
More posts
- exporting1 day ago
- light and shade2 days ago
- day nigh cycle13 days ago
- game making17 days ago
- collision21 days ago
- classes and oop29 days ago
- trajectories30 days ago
- fullscreen (LÖVE2D only)32 days ago
- general base of project33 days ago
Leave a comment
Log in with itch.io to leave a comment.