Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the fastest way to find the point of intersection between a ray and a polygon?

Pretty much as the question asks. Answers preferably in pseudo code and referenced. The correct answer should value speed over simplicity.

like image 865
Chris Lloyd Avatar asked Nov 23 '08 09:11

Chris Lloyd


1 Answers

See Intersections of Rays, Segments, Planes and Triangles in 3D. You can find ways to triangulate polygons.

If you really need ray/polygon intersection, it's on 16.9 of Real-Time Rendering (13.8 for 2nd ed).

We first compute the intersection between the ray and [the plane of the ploygon] pie_p, which is easily done by replacing x by the ray.

 n_p DOT (o + td) + d_p = 0 <=> t = (-d_p - n_p DOT o) / (n_p DOT d)

If the denominator |n_p DOT d| < epsilon, where epsilon is very small number, then the ray is considered parallel to the polygon plane and no intersection occurs. Otherwise, the intersection point, p, of the ray and the polygon plane is computed: p = o + td. Thereafter, the problem of deciding whether p is inside the polygon is reduced from three to two dimentions...

See the book for more details.

like image 137
Eugene Yokota Avatar answered Oct 02 '22 21:10

Eugene Yokota