map files

Started by
2 comments, last by SirKnight 22 years, 3 months ago
Im writing a .map file compiler and does anyone know how to tell if two planes are parallel? When i project a big polygon on a plane and loop through all the other planes to clip against, i need to check if one of the planes is parallel to the plane the polygon is projected to since no intersection would occur. -SirKnight
Advertisement
One way to tell is to test for parallel normals. That is, if the normals are in the same or in exactly opposing directions, the planes are parallel. To find the normal to a plane, you simply take the cross product of two vectors contained in the plane.. which you can get with 3 non-colinear points of the plane. Sorry if that''s confusing.. it''s kind of late. I''ll clarify if you like.

-----
Riley Lark
"Drinking more Dr. Pepper before 9 AM than most people drink by 9:30."
--Riley

AND:

you will have to take floating point
rounding errors into consideration.
maybe two planes are actually parallel,
but it''s likely the case that two values
you compare (after some cross and dot products)
may almost never be absolutely equal.
you should use some tolerance value.
IE the values differ about 0.00001 or so,
even if the planes are originally parallel.
instead of a straight comparison of two values
you could do that:

difference = abs( value_1 - value_2 );

if ((difference > -tolerance)&&(difference < +tolerance)
{
// within bounds
// consider parallel
}




oh, I didn't see that the poster before me
didn't finish.

if you have one, say, rectangular polygon with the points
A,B,C,D,
you could get two vectors that define it's plane
by doing vectorial subtracions like that:

v1 = B-A
v2 = D-A
where A ist the first and D the last point of the polygon,
named in a "circular" order (counter-/or clockwise)

now you do the crossproduct: vn = v1 x v2
vn is the normal vector of the plane


if you have tWo planes to test, and calculated
the normals of each, you could make unit vectors
of them: scale them by their 1/length.

then, compare every component of the one vector
with the corresponding component of the other vector.
(with that tolerance stuff I described in my last post)
IE vn1.x and vn2.x, vn1.y and vn2.y and the z's
If *every* of the three components are (nearly, like said)
equal, the vectors are pointing into same direction,
thus, the planes are parallel.

If not,
scale ONE of the two normals by -1.0,
to change it's direction about 180 degrees.

now compare both again, if now all values are (nearly)
equal, the original vector was pointing (before changing)
exactly into opposite direction, thus they're parallel,
too.



hope this helped.






Edited by - UnshavenBastard on January 14, 2002 4:58:03 AM

This topic is closed to new replies.

Advertisement