Choosing normal when ordering counter clockwise

Started by
0 comments, last by phil_t 11 years, 8 months ago
Hello all,

I'm having trouble choosing the normal vector to order my triangle vertexes.

So I have the 3 points that define a plane, I did the subtraction - got 2 vectors, did cross product got the normal.
My problem now is I don't understand how to choose between the ordering I get and the opposite to make sure I define a surface that is from above, just like a terrain.

Some psedo-code to explain better:
[source lang="java"]private boolean isCounterClock(Vector3f p1, Vector3f p2, Vector3f p3) {
Vector3f a1 = p1.subtract(p2);
Vector3f a2 = p3.subtract(p2);
Vector3f normal = a2.crossLocal(a1).normalizeLocal();
// the normal vector for the downwards face must always have negative y
if (normal.y < = 0f) {
return true;
}
else {
return false;
}
}
[/source]

What am I doing wrong?
Advertisement
I usually order my vectors so they are in sequence (e.g. p2-p1, and p3-p2), but what you have looks like it will work too. What's the problem exactly?

Note that you are describing the specific case when the triangle is being viewed from the +ve y axis. In the general case you would dot the normal with the vector that points toward the viewer (which in this case is (0, 1, 0)), and test if the dot product is +ve or not.

This topic is closed to new replies.

Advertisement