有A,B,C,三点,判断该3点为什么顺序排序。
利用矢量叉积判断是逆时针还是顺时针。
设A(x1,y1),B(x2,y2),C(x3,y3),则三角形两边的矢量分别是:
AB=(x2-x1,y2-y1), AC=(x3-x1,y3-y1)
则AB和AC的叉积为:(2*2的行列式)
|x2-x1, y2-y1|
|x3-x1, y3-y1|
值为:(x2-x1)*(y3-y1) - (y2-y1)*(x3-x1)
利用右手法则进行判断:
如果AB*AC>0,则三角形ABC是逆时针的
如果AB*AC<0,则三角形ABC是顺时针的
如果…… =0,则说明三点共线,
1 2 3 flag=(x2-x1)*(y3-y1)-(y2-y1)*(x3-x1); 4 if(flag<0) printf("1 "); 5 else printf("0 ");
1为顺时针;0为逆时针。