Reputation: 333
I am trying to find out how to compute the azimuth and elevation angles from a moving air-vehicle simulation to some point on the ground.
I have the vehicle's position vector P, and its orientation quaternion vehQ. I have the target position T, and I have built the difference vector dPT by subtracting P from T.
How do I go about computing the az/el angles to the target? As you can guess, I am not very familiar with 3D math, so some helpful explanation would be wonderful.
Thanks
Upvotes: 3
Views: 4100
Reputation: 26107
First, find the relative position vector dPT
from vehicle to target:
worldspace target vector dPT = T - P
Since vehicle position P
and target position T
are in world coordinates, the resulting vector dPT
will also be represented in world coordinates. So, you must use the vehicle orientation quaternion to rotate dPT
from world coordinates to vehicle coordinates. The correct way to do this depends on the conventions used by whatever generated your quaternion, but the math is likely to be one of the following:
vehicle target vector U = vector_part( vehQ * quaternion(0,dPT) * conjugate(vehQ) )
or
U = vector_part( conjugate(vehQ) * quaternion(0,dPT) * vehQ )
Since you have provided no information on your quaternion convention, I have no way to know which one of these is correct for your application. However, it is highly likely that your quaternion source also provides functions or methods for using its quaternions to rotate vectors. So, what you should actually do is locate these functions, read their documentation, and try using them before rolling your own.
Once you have your target vector in vehicular coordinates, you can use standard formulas for finding azimuth and elevation angles. This depends on your coordinate conventions, but as an example, if your coordinate convention is right-handed with the Z-axis as the "up" direction:
azimuth = atan2(U.y, U.x)
elevation = atan2(U.z, sqrt(U.x^2 + U.y^2))
This should calculate an elevation in radians ranging from -PI/2
to +PI/2
, and an azimuth in radians ranging from -PI
to +PI
, with 0 along the +x axis, and increasing counterclockwise (as long as the elevation is not vertical...).
Upvotes: 4