Counter-clockwise vertex winding

Short story: I have 3 vertex (on a 2d plane) that I need to layout in a “counter-clockwise winding” way. Is there some math trick to do that?

Long story: I’m making the workflow to make 2d collidable shapes out of images (inkscape->blender->jme sdk->my tool) Hitbox building · MonkeySheet workflow

But the problem is that the shape is upside down. I changed the sign of the y but then I got the winding problem… so I tried to invert the order but not always work :frowning:

You can check to see if a triangle is wound properly by getting the cross product of two of the legs. It will point up or down depending on winding.

If it’s the wrong way then swap two of the vertexes.

Thanks! But do you mean
v1.cross(v2)
or
v2.subtract(v1).cross(v3.subtract(v2))

That’s two vertexes.

That’s two legs.

But it’s probably important that legs share the root vertex.
v2.subtract(v1).cross(v3.subtract(v1))

If that points the wrong way then you can swap v2 and v3.

2 Likes