I need to implement correct translation of an artificial horizon line in a circle with a specified radius using LUA. I need equasions for each of the 4 points of the line (x1, y1, x2, y2)
Any ideas? I cannot even wrap my head around the concept.
Thank you in advance!
I assume your X axis goes to the right and Y axis goes to the top.
local max_pitch = 50 -- at pitch=50° horizon goes beyond the circle
local radius = 100 -- circle radius
local center_x, center_y = 200, 150 -- circle center
function draw_horizon(banking_angle, pitch_angle)
local alpha = math.acos(-pitch_angle/max_pitch)
if alpha == alpha then
local beta = math.rad(90 - banking_angle)
local x1 = center_x + radius * math.cos(beta + alpha)
local y1 = center_y + radius * math.sin(beta + alpha)
local x2 = center_x + radius * math.cos(beta - alpha)
local y2 = center_y + radius * math.sin(beta - alpha)
drawline(x1, y1, x2, y2)
else
-- horizon is beyond the circle
end
end
-- current angles
local banking_angle = -40 -- 40° (positive right, negative left)
local pitch_angle = 10 -- 10° (positive climb, negative dive)
draw_horizon(banking_angle, pitch_angle)