Planar faces

Started by
2 comments, last by fig 17 years, 8 months ago
If I have 2 triangles that make a face, how can I check if this face is planar? Then I need to the actually make the face planar. I haven't got the first clue where to start, so any advice is welcome. I'm using this to build a race track, so these faces are joined in a strip like fashion. My problem started when I tried to add banking on the corners. The vertices between each face are shared and because the faces aren't planar, I get a step effect on the track, which wouldn't be usable. I tried turning the edges of the triangles and also using quads, but it still happens. I can post screenshots etc. if I haven't described problem well enough..
Advertisement
I would try checking to see if the normals for the triangles are the same or if the angle between the normals is 0.
www.lefthandinteractive.net
To test if four points P0, P1, P2, P3 are coplanar, you can create three vectors:

V0 = P1-P0
V1 = P2-P0
V2 = P3-P0

Then compute the triple scalar product: Dot( Cross(V0,V1), V2 ). If the result is near 0, then they might be coplanar. However, they could be collinear. To check for that, do Cross(V0,V1) and Cross(V0,V2) -- if both results are near zero, then they're collinear.

If they're not coplanar, you'll need to project one of the points, say P3, to the plane formed by the other three, say P0, P1, P2. The plane normal n = (a,b,c) is just Normalize( Cross(V0,V1) ) -- which you should already have from your coplanar test, you just need to normalize. The plane offset d is -Dot( n, P0 ).

Then to project, you do:

distance = Dot( n, P3 ) + d;
newP3 = P3 - distance*n;

I think there's a way to do this without the normalize -- I'll have to work it out. Probably still involves a floating point division, though.

Btw, you'll never get four points 100% coplanar unless they're normal to one of the coordinate axes (e.g. they all have the same z coordinate), due to floating point precision error. So that's why you need to check for "near zero."
That worked perfectly.

I had an error in the code that rotated the vertices to make the track bank to the left and right. It made it seem as if it didn't work quite right at first.

Thank you.

This topic is closed to new replies.

Advertisement