# polygon/triangle in clockwise order

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

## Recommended Posts

Hello all. Do anyone know a good way to sort and check if a polygon/triangle is in a clockwise order? /Luger

##### Share on other sites
Depends on what you mean. There's no such thing as a polygon that is inheritly "clockwise" in order. It depends on the angle from which you view it at. That's how backface culling works in most graphics API's.

##### Share on other sites
I know, just had a small error in my code, and everything works now.... =)

##### Share on other sites
First, note that a triangle ABC can only be classified as clockwise or counterclockwise as viewed from a given position P not in the plane of the triangle.

So, given ABC and P, you can do this:

Vector normal = Cross(B - A, C - A);bool counterclockwise = Dot(normal, P - A) > 0;

What P is depends on your application. It might be the camera position, the world origin, a vertex of some other triangle, or something else entirely.

If your triangle is not in 3D but in 2D, you can simplify the test accordingly (knowing that z = 0).

1. 1
Rutin
28
2. 2
3. 3
4. 4
5. 5

• 11
• 13
• 11
• 10
• 13
• ### Forum Statistics

• Total Topics
632952
• Total Posts
3009438
• ### Who's Online (See full list)

There are no registered users currently online

×

## Important Information

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!