Just calculate the winding direction of triangle ABC

therefore, if you calculate normal n=(B-A)x(C-B), where xis the transverse product, then the sign n.zdetermines the direction.
n.z = ((B.x-A.x)*(C.y-B.y)) - ((B.y-A.y)*(C.x-B.x))
if (n.z<0.0) dir=CW else dir=CCW;
that's all you need ( CW means clockwise and CCW counterclockwise) rude, if your coordinate system is different, then rotation can be denied
[Note]
if (n.z==0), then the points B,Care either opposite or identical, so the direction does not matter, since both ways the angular distance is the same
source
share