# Planar faces

This topic is 4456 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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..

##### Share on other sites
I would try checking to see if the normals for the triangles are the same or if the angle between the normals is 0.

##### Share on other sites
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."

##### Share on other sites
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.

1. 1
Rutin
46
2. 2
3. 3
4. 4
5. 5

• 11
• 9
• 12
• 10
• 13
• ### Forum Statistics

• Total Topics
632988
• Total Posts
3009736
• ### Who's Online (See full list)

There are no registered users currently online

×