Orthogonal projection onto a straight line
[posp, alpha] = CL_gm_projLine(pos1, pos2, pos)
This function computes the image of a point by an orthogonal projection onto a straight line.
The straight line is defined by two points: pos1 and pos2.
The point to be projected is pos.
The image of pos by the projection is defined by:
posp = pos1 + alpha * (pos2 - pos1)
The vector [pos, posp] is by definition perpendicular to the segment [pos1, pos2].
If alpha belongs to the interval [0,1], then posp then belongs to the segment [pos1, pos2].
Notes:
- If pos1 and pos2 are (almost) identical, the line passing through pos1 and pos2 is undefined, and therefore the results are also undefined (that is %nan).
- Empty results are returned if one of the input arguments is empty.
Application:
This function can be used to compute the distance between a straight line (defined by 2 points: pos1 and pos2) and a sphere (of radius R and center pos). The distance (supposed to be positive) is simply: ||posp - pos|| - R, with posp = CL_gm_projLine(pos1, pos2, pos).
Points defining the straight line. (3xN or 3x1)
Point to be projected. (3xN or 3x1)
Image of pos by the projection. (3xN)
Coefficient defining the projeted point (see above for details). (1xN)
CNES