I have a line in 3D defined by point P0 and direction vector D. For given input point P on a line defined as above, I want to test if P is in front of point P0. The code will be used in GLSL fragment shader.
So far, my best solution is following GLSL function:
bool IsInFront(vec3 P, vec3 P0, vec3 D)
{
float d = length(P - P0);
vec3 Pp = P0 + d * D;
return (length(Pp - P) < 1.0E-4);
}
Explanation is simple. d is distance between P and P0, and there are only two possible positions on a line where a point with distance d from point P0 can be on a line: in front, or behind point P0. Then I just check if positive point is same as input P.
However, this code uses precision 1.0E-4, and recalculation of input point P. Is there a faster and numerically more stable way to do this?
Regards