Heading of my Y-axis at 90° pitch?

Zatnikitelman

Addon Developer
Addon Developer
Joined
Jan 13, 2008
Messages
2,302
Reaction score
6
Points
38
Location
Atlanta, GA, USA, North America
It should be clear by now that I stink at coordinate conversions :p. Again, I'm having trouble with knowing how to convert. This time, I need to find what heading my Y-axis is pointing to while my Z-Axis points at the Zenith. Orbiter has the HorizonRot() function, but I'm not exactly sure what that would give me. How do I find the heading of my Y-axis when the ship is vertical?
Thanks for any help,
Zatman
 

SiameseCat

Addon Developer
Addon Developer
Joined
Feb 9, 2008
Messages
1,699
Reaction score
1
Points
0
Location
Ontario
I think you could use
Code:
VECTOR3 v;
HorizonRot(_V(0, 1, 0), v);
double angle = PI-atan2(v.x, v.z);
The HorizonRot function will convert the y-axis vector to horizon-relative coordinates, so v will be in the xz-plane. Then, you can use atan2 to get the angle between the vector and the x axis. If you're heading is 00, the y-axis will be (0, 0, -1) in the horizon frame, so you need to subtract the result from 180 degrees to correct for this.

The code above should work, but I haven't tested it, so there might be a subtle mistake (i.e. signs) somewhere.
 

Zatnikitelman

Addon Developer
Addon Developer
Joined
Jan 13, 2008
Messages
2,302
Reaction score
6
Points
38
Location
Atlanta, GA, USA, North America
Thanks SOOO much SiameseCat! I had to multiple by Orbiter's DEG, then subtract 180 from it and toss in an If statement to get heading from 180 to 360 properly so the final code looks like this:
Code:
VECTOR3 v;
HorizonRot(_V(0,1,0),v);
double angle = (PI+atan2(v.x,v.z))*DEG-180;
if(angle<=0)
   angle+=360;
Again, thanks so much for the help. Eventually, I'll figure this stuff out.
Thanks! :)
 

SiameseCat

Addon Developer
Addon Developer
Joined
Feb 9, 2008
Messages
1,699
Reaction score
1
Points
0
Location
Ontario
You can change the third line to
Code:
double angle = atan2(v.x, v.z)*DEG;
Adding Pi and subtracting 180 degrees will cancel each other out (taking into account radian to decimal conversion).
 
Top