C
If you get the crossed product from the segments on both sides of the angles, and take your signal, you will have the information of what sense the points are oriented, as shown below.// == 0: colineares; > 0: horario; < 0: anti-horario
int ordem(double ax, double ay, double bx, double by, double cx, double cy) {
double bax = ax - bx;
double bay = ay - by;
double bcx = cx - bx;
double bcy = cy - by;
return (bax * bcy - bay * bcx);
}
int main()
{
printf("P1, P2, P3 como em SOpt_125794: %d\n", ordem(5, 0, 0, 2, 5, 4));
printf("P3, P2, P1 como em SOpt_125794: %d\n", ordem(5, 4, 0, 2, 5, 0));
printf("Colineares em sequencia: %d\n", ordem(0, 0, 1, 1, 2, 2));
printf("Colineares com terceiro ponto no meio: %d\n", ordem(0, 0, 4, 4, 2, 2));
return 0;
}
Note that comparing exactly with zero can give you some false results because of the floating point approach, so if you need a higher accuracy, you can use something of the type (colinears if abs(order) < epsilon), where epsilon is a very small value.