How to determine whether a polygon is above, below or inside of another polygon?

67 Views Asked by At

I'm writing a BSP tree program. How do I classify a polygon as above or below a plane?

I don't know much about Matrix or Vector math so if it the answer does involve it could you explain how it pertains to classifying polygons?

1

There are 1 best solutions below

0
On

Lets say we have a plane with normal n = (n1, n2, n3) and d its perpendicular distance from the origin.

If you have a point x that is on the plane, then

x1n1 + x2n2 + x3n3 = -d

if d has a positive or negative sign is not strictly defined. But we can formulate this as

x1n1 + x2n2 + x3n3 + d = z

if z>0 then a point is above the plane.

Now for a polygon p we have to do this for all points/vertices, lets stay in 3D we get 3 values for z.

if all(z > 0):
   p is above
else if all(z < 0):
   p is below
else
   p is cut by the plane

NOTE: Depending on the setting errors from floating point arithmetics can be relatively high and even up to ~1e-2 for points that are actually on the plane.


A similar question and answers can be found here and some hints on alternate forms.