#### Archived

This topic is now archived and is closed to further replies.

# triangle

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

## Recommended Posts

How can i get The winding of a triangle in 3d ?

##### Share on other sites
The winding number is a 2D beasty, and to find it you have to project the triangle and point of interest into a plane. For example, a 3D point may be inside or outside a 3D triangle depending on from where you look.

Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.

##### Share on other sites
I''m not taking about a 3d test point i want to know if a triangle is clockwise or counterclockwise given 3 triples in space

##### Share on other sites
Okay,

Still depends on where you''re looking from. Any triangle will appear to be clockwise from one side, counterclockwise from the other.

Lets look at how the normal of a triangle is calculated. The triangle has points 1, 2, and 3. You can find a normal by crossing the vector from 1-2 with the vector from 1-3. If you do this, then the normal will point to the side of the triangle that makes it appear counterclockwise. That is, if you look towards the triangle from the side the normal points to, the triangle will look counterclockwise. If you look from the other side, the triangle will be clockwise.

Choose a look-at direction. This is a vector from, say, a camera, to one of the triangle vertices. Dot this look-at vector with the normal calculated above. If the dot product is negative, the triangle is counterclockwise from your pointer of view. It the dot product is positive, the triangle is clockwise from your point of view.

Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.

##### Share on other sites
Ok, i''ll go deep in that , i have some 3ds file that are double faced that''s to say some traingles have the winding reversed
when i import them, i have to find a way to see if some
triangle is facing right if not , reverse the triangle indicies .
that''s why i need to know if a triangle is counterclockwise or not.

##### Share on other sites
That''s a bad situation, since you can''t pick a single viewpoint that''ll work for all triangles. If the geometry is fairly simple, you might try the centroid of the object.

##### Share on other sites
One method I just thought of:

Pick (and tag) a single triangle that is facing the correct direction. Then find other triangles that share a side with that one and are facing the same way (they should have two and only two same vertex values, but in the opposite order). Tag those as well. Recursively continue in this manner, tagging as you go, until all faces in a specific direction are tagged (no more valid boundaries). then delete untagged triangles. this should work well for well-behaved geometry.

##### Share on other sites
Once again, pardon my horrendous ASCII art...

  1 ________H /\ / \ / \2 / \\ 3 ----------

So you've got a triangle. Pick the first vertex, any vertex. (Assume my first top one.) Create a fictious horizontal line from that vertex.

Take the second vertex of the triangle and compute the angle between the horizontal line and the segment between the first and second vertexes. Make it such that the angle is between 0° and 360°. Do the same for the third vertex.

If <H12 is less that <H13 (as mine is above), it is counterclockwise. If <H12 is greater that <H13, then clockwise.

~ Dragonus

Edited by - Dragonus on August 21, 2001 3:04:47 PM

##### Share on other sites
Yes, i have already tried with the centroid ( placed at 0,0,0 )
but this works for convex and enclose geometry a cube or a sphere
i think this isn''t a np-complete problem.
i have tried also with the direction of the normal , but
towards which viewer ? then projecting the triangle oacross
the 3 planes and finding the signed are for each plane
using a bitmask to see if all of them contain the same singed area but this is not working....

##### Share on other sites
Ignore my ascii art above. Doesn''t like it when I edit the message... Here''s the real deal...

  1 ________H /\ / \ / \2 / \ 3 ----------

##### Share on other sites
I like Sneftel''s approach, and it should work well as long as your model is relatively smooth and if you deal with each separate mesh object individually.

Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.

##### Share on other sites
The only problem is drawing a line passing from a point which
has the components normal to the surface normal
that''s to say a*l+b*m+c*n = 0 and this is not an easy task
it works if the triangle is aligned with some axis