In aviation, runways are named according to their magnetic orientation seen from the pilot's perspective. For example: a strip of asphalt oriented along the east-west axis will be named 9
for the pilot coming from west (east is at 90° from North) and 27
for a pilot coming from east (west is 270° from North).
When several runways have the same orientation, the naming convention uses letters L/C/R for distinguishing between the Left/Centre/Right ones (look at the 22
runways in the capture above).
In the game I'm coding, I chose to describe runways by the following three attributes:
- Orientation (between 0° and 180°).
- Position of their geometrical centre relative to the aeroport one.
- Length
With this data I'm able to generate all the touchdown points and give them the correct number, but I can't find a straightforward method to assign the correct letter, as I could not think to a straightforward way to mathematically determine which one is "left/centre/right" from a "landing pilot's perspective".
So the question is:
Is there a simple, straightforward vector formula that - given two parallel vectors pointing in the same direction - will return the leftmost (or rightmost) one?
Please note that this question is really about the straightforwardness of the formula, as I already found a non-straightforward way to get the result, but I would like to find a more elegant way to solve the problem.
Many thanks in advance for your expertise and contributions!
Answer
Of course there is. Compute the determinant of the orientation vector of the runways and the vector from one runway centre to another, the result will be positive or negative depending on which runway are to the right of the other.
Calculation of determinant for a pair of 2D vectors:
Det(A,B) = Ax*By - Ay*Bx
There is a load of other stuff one can learn about the use of determinants, but for this purpose it's all you need to know.
Edit, same thing in different words:
Compute the dot product of the orientation vector of the runways and the tværvector of the vector from one runway centre to another, the result will be positive or negative depending on which runway are to the right of the other.
DotProduct(A,B) = Ax*Bx + Ay*By
A tværvector is the rotation of a 2D vector 90 degrees counter-clockwise. The tværvector T of A is calculated as follow:
Tx = -Ay
Ty = Ax
Edit, I guess I should try to explain why this works.
The result of a dot product is equal to the product of the length of the two vectors, by the cosine of the angle between them. Since lengths are always positive and cosine is positive for angles in the range ]-90 deg; 90 deg[
the dot product is positive for acute angles, and negative for obtuse angles.
Imagine two parallel lines and a vector from any point on line 1 to any point on line 2, this vector may point in any direction within a 180 degrees arc, except from the two extremes. If we rotate this vector 90 degrees we also rotate the arc 90 degrees. This rotated arc is positioned exactly so that a vector parallel to the lines will either have an acute angle to all vectors within the arc, or an obtuse angle to all of them, depending on the position of the lines and the direction of the vector. Since the dot product works as an acute/obtuse test it can be used to tell whether a line is to the right of left of another, depending on which direction you look at them.
No comments:
Post a Comment