Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I clip a line segment against a frustum?

Tags:

math

clipping

Given two vectors A and B which form the line segment L = A-B. Furthermore given a view frustum F which is defined by its left, right, bottom, top, near and far planes.

How do I clip L against F?

That is, test for an intersection and where on L that intersection occurs? (Keep in mind that a line segment can have more than one intersection with the frustum if it intersects two sides at a corner.)

If possible, provide a code example please (C++ or Python preferred).

like image 673
MHOOO Avatar asked Sep 16 '08 22:09

MHOOO


1 Answers

I don't want to get into writing code for this now but if I understand "frustum" correctly the following should work.

  1. Intersect the Line with all given planes
  2. If you have two intersections you're done.
  3. If you have only one intersection calculate the front plane and intersect.
  4. If you still have only one intersection calculate the back plane and intersect.

But I may have completely misunderstood. In that case please elaborate :)

like image 86
Sarien Avatar answered Oct 05 '22 23:10

Sarien