# Counter-Clockwise/Clockwise Vertices

This is a discussion on Counter-Clockwise/Clockwise Vertices within the C Programming forums, part of the General Programming Boards category; I am implementing the marching cubes algorithm and I need to have a way to make sure the vertices are ...

1. ## Counter-Clockwise/Clockwise Vertices

I am implementing the marching cubes algorithm and I need to have a way to make sure the vertices are put into the triangle array in either a clockwise or counterclockwise order (as long as it is consistent for each triangle). I need this for lighting when the triangles are constructed. How would I do this? Is there a function that I can use (or make) that is given 3 vertices that have an x,y, and z component that makes sure they are in counter clockwise or clock wise order?

I saw something similar here:
Projects &gt Marching Cubes

but I didn't really understand it and it's in C++ (I'm just using C)

Thanks!

If more information is needed or something is unclear let me know.

2. You can use the dot product to get the angle between two vectors (vector1 is point2 - point1, and vector2 is point3 - point1). The link provided gives the formula for the angle. Just check the angle's sign to determine whether the order is clockwise or counterclockwise.