Vector vector addition and subtraction:
Let the two-dimensional vector P = ( x1, y1 ) and Q = ( x2 , y2 ).
Then vector addition is defined as: P + Q = ( x1 + x2 , y1 + y2 ), and vector subtraction is defined as: P - Q = ( x1 - x2 , y1 - y2 ).
Dot product of vectors:
P=(x1, y1), Q=(x2, y2). but
cross product of vectors
Let the vector P = ( x1, y1 ), Q = ( x2, y2 )
Then the vector cross product is defined as the signed area of the parallelogram consisting of (0,0), p1, p2, and p1+p2 .
Use the cross product of vectors to determine the direction of a vector.
If P × Q > 0 , then P is in the clockwise direction of Q.
If P × Q < 0, then P is in the counterclockwise direction of Q.
If P × Q = 0 , then P and Q are collinear, but may be in the same direction or in the opposite direction.
Strictly follow the counterclockwise direction to calculate the area
Doesn't this area overlap ?
Note that the value of triangle DEA + triangle DAB calculated by cross product is negative, while the value of triangle DBC calculated by cross product is positive, which is equivalent to removing the overlapping part.
ans += (a[i] \* b[i + 1 ] - a[i + 1 ] \* b[i]); // a[] is the x coordinate, b[] is the y coordinate, the analog vector is similar take
Reprinted in: https://www.cnblogs.com/kamimxr/p/11559752.html