matrixgeometrytrigonometryprojectionalgebra

Is it possible / practical to convert a 3d line segment to a point in 2d so that I can easily measure points from it's origin?


Consider the following scenario:

desired plane conversion

I have a line segment in 3d to track an ideal approach to a given runway. Aircraft's objective is to try to fly ON this particular line into the touchdown zone, however, no one is perfect, and players will inevitably fly too high, too low, to far to the left, or too far to the right of this line.

My goal is to identify if a player is too high, too low, too too far to the left, or too far to the right. and do something if the player is too far in any given side (this includes printing to the player that they're too high or too low).

The question: (Considering the above illustration:) If I have a given a cartesian line segment in 3d space (line = x, y, z && line2 = x1, y1, z1) and a player's point relative to the line (also in 3d space), does it make sense / is it practical to convert the 3d line to a singular point on its own axis (origin 0, 0) and measure the distance to the player's point relative to the origin? If so, how could I approach converting this 3d line in a fixed dimension to a point in a separate dimension.

My thought process: Every 2d line can be represented as a point in 1d so long as we're looking down the line. If we do this and make that point the origin of a 2d grid, measuring relative distance becomes easy.

I think it's possible to also use other methods / approaches such as cross products, but if this is cheaper, I'd prefer to use this method.

Anyways, I'd love to hear your feedback. Please let me know what you think! Note: I'm using lua

I've seen some mentions of homogenous coordinates, but I've noticed that because the axis is fixed despite a desired rotated axis, it causes issues in various conditions.
Measuring a distance to closest point on the line is simple, but not so much when trying to identify if it's left or right / up or down relative to the line.


Solution

    1. create basis vectors X right,Y up

      you can use local ground normal n, line (p0,p1) direction and cross product to do this

      X = cross( n , p1-p0 );
      Y = cross( n , X ); Y /= |Y|;
      X = cross( Y , n ); X /= |X|;
      
    2. convert

      x = dot( p-p0 , X )
      y = dot( p-p0 , Y )
      

      now x,y is signed distance from your line aligned to your wanted directions...

    [edit1] moved from comments...

    Anyway if you want signed scalar distance d along some unit vector v from some starting point p0 of some point p then it is:

    d = dot(v,p-p0);
    

    now you just provide vector v along whatever you want to measure the distance. As your ground is plane z=0 using parametric circle equation (using azimuth as parameter) you get vector along your runway

    (cos(azimuth),sin(azimuth),0)
    

    if you want the vector left/right you just rotate it by 90 deg so either use azimuth + PI/2 or swap x,y and negate one for example

    (-sin(azimuth),cos(azimuth),0)
    

    if you want up vector its just (0,0,1)

    From what you describe now you want axis Y to be perpendicular to your approach line (p0,p1) and point up (angled) so you can exploit cross product which will return perpendicular vector to its operands so:

    Y = cross(p1-p0,cross(p1-p0,(0,0,1))); Y/=length(Y);
    

    the internal cross cross(p1-p0,(0,0,1)) will be the same as X if the approach line is aligned to your runway...