views:

97

answers:

1

Two lines in 3d are projected onto 2d screen, and their projections intersect at a point which can be calculated.

If the endpoints of the lines in 3d space are known and their intersection point in the projection plane is also known, how can I determine which line is in front at this intersection point?

A: 

As a naive solution, you can unproject the intersection point into 3D space as a segment(from zNear to zFar) and intersect this line with both of your test lines, taking the closer intersection.

edit: A bit more in-depth, you know your ray will intersect both lines when you form it so you can form a plane with the four points (two points for the projected segment and two points from the endpoints of your test line segment) and now your intersection test can be done in 2D using the standard parametric line equation.

This site has samples for line-line intersection.

Ron Warholic