Conversion from machine-local polar coordinates (yaw, pitch, roll) to global (azimuth, elevation)

142 Views Asked by At

I'm writing a 3D LOGO module in Python.

I recently realized that my approach is flawed. What I implemented is: the turtle besides right/left commands which change its azimuth in the xy plane, received 'up' / 'down' which change the elevation - angle between xy plane and where the turtle is pointing. I got it to work, but realized this approach is very limiting - current position of the turtle doesn't affect the two angles, a turtle pointing straight up, told 'left 90' will be still pointing the same straight up, until lowered.

I'd like to implement something more akin to airplane controls. Pitch up/down, yaw left/right, roll clockwise/counterclockwise, and effects all depend on current position: a pilot oriented due north, performing pitch up 90 degrees, then yaw left 90 degrees will be facing due west, but is rolled 90 degrees - and should perform roll clockwise 90 degrees to return to level flight. Similarly, starting in flat flight after roll 180 degrees, input of pitch up (yoke back) results in plane's motion to pitch down.

How do I convert these operations (pitch up/down, yaw left/right, roll cw/ccw in the plane's frame of reference) to azimuth and elevation (and spin angle) in global frame of reference?