Does default OpenGL perspective projection matrix preserve straight lines in all three dimension?

Viewed 153

I know that the default OpenGL perspective projection matrix preserves straight lines at least in XY - so if three points are colinear in eye-space, the XY coordinates of the three points in NDC will also lie on a straight line - but what about XYZ in NDC? Will the XYZ coordinates of the projected points still be colinear (I'm asking because to me it currently looks like they're not, but I might be wrong)

If not, is there a way to change the projection matrix so that the post-projection points will have this property?

1 Answers

Proof by geometric argument

For any line L, there is a plane S that contains all the points in L and the origin O.

Any line connecting a point P in L and the origin is also contained in S. So the projection will be in the intersection between the plane S and the plane z=1, and that's a straight line.

Using equations

Usually the projection will map (x, y, z) to (x / z, y / z), for the camera at the origin, pointing to z direction.

Consider the parametric equation of the straight line being (a * t + cx, b* t + cy, c*t + cz), the derivative of the curve in 3D will be (a,b,c), in the 2D space you have

dx/dt = ((c*t+cz)*a-(a*t+cx)*c)/((c*t+cz)^2) = (cz*a-cx*c)/z^2

dy/dt = ((c*t+cz)*a-(b*t+cy)*c)/((c*t+cz)^2) = (cz*a-cy*c)/z^2

If you divide (dx/dt)/(dy/dt) = (cz*a-cx*c) / (cz*a-cy*c).

This will draw a curve that with tangent to a constant direction, a.k.a straight line.

Related