check if point is left or right of vector

To check if a point is left or right of a vector, you can use the cross product between the vector and the point. Here are the steps:

  1. Define the vector: A vector can be defined by two points, let's say point A and B. The vector is the difference between these two points: V = B - A.

  2. Calculate the cross product: To calculate the cross product between the vector V and the point P, you can use the following formula:

crossProduct = (P.x - A.x) (B.y - A.y) - (P.y - A.y) (B.x - A.x)

where P.x and P.y are the coordinates of the point P, and A.x, A.y, B.x, B.y are the coordinates of the points A and B respectively.

  1. Check the sign of the cross product: If the cross product is positive, the point P is on the left side of the vector V. If the cross product is negative, the point P is on the right side of the vector V. If the cross product is zero, the point P is collinear with the vector V.

if (crossProduct > 0) { // Point is on the left side of the vector } else if (crossProduct < 0) { // Point is on the right side of the vector } else { // Point is collinear with the vector }

Note that if the points A, B, and P are in a counterclockwise order, the point P will be on the left side of the vector. If they are in a clockwise order, the point P will be on the right side of the vector.

This method works because the cross product gives you a signed area of the parallelogram formed by the vector V and the point P. The sign of the cross product determines the orientation of the point relative to the vector.