1. The cross product of P (x1, Y1) and Q (X2, Y2) is:
P × q = (x1 * y2-x2 * Y1 );
If the result is greater than 0, P is clockwise in Q.
If the result is <0, P is in the counterclockwise direction of Q.
Equals to collinearity
Determine whether a point is in the Triangle
Int isintriangle (INT X1, int Y1, int X2, int Y2, int X3, int Y3, int pedx, int Pedy)
{
Int sz1, sz2, sz3;
Sz1 = (x2-x1) * (pedy-y1)-(pedx-x1) * (y2-y1 );
Sz2 = (x3-x2) * (pedy-y2)-(pedx-x2) * (y3-y2 );
Sz3 = (x1-x3) * (pedy-y3)-(pedx-x3) * (y1-y3 );
If (sz1 <0 & sz2 <0 & sz3 <0)
{
Return 1;
}
Else if (sz1> 0 & sz2> 0 & sz3> 0)
{
Return 1;
}
Return 0;
}
3D:
P (x0, y0, z0), u (x1, Y1, Z1 );
P * u = <y0 * z1-y1 * z0,-x0 * Z1 + X1 * z0, x0 * y1-x1 * y0>
The result is a normal vector;
2. When vector forks and products are required, you should assume that you are in the left-hand or right-hand coordinate system, and then use handshakes.
(The thumb points to the desired vector direction. The other four fingers indicate the direction of Bending. The left-hand coordinate system is clockwise and the right-hand coordinate system is counterclockwise)