Check the side of a vector

517 Views Asked by At

enter image description here

As above diagrams shows I have two vector U and V. I want to determine weather V vector is in A side or the B side it means form the left side of the right side to the U vector.

I need some help to sort out this. thanks in advance!

1

There are 1 best solutions below

4
On BEST ANSWER

so... do you mean you want to know weather the point $\left(x_{2},y_{2}\right)$ is on the left or on the right of the line passing $\left(x_{1},y_{1}\right)$ and $\left(x_{3},y_{3}\right)$? In this case:

define a normal pointing always to the same side of your line passing the two points $\left(x_{1},y_{1}\right)$ and $\left(x_{3},y_{3}\right)$, that would mean any vector perpendicular on $\left(r_{x},r_{y}\right):=\left(x_{3},y_{3}\right)-\left(x_{1},y_{1}\right)$.

For instance $\left(s_{x},s_{y}\right):=\left(r_{y},-r_{x}\right)$ does it. this vector should point to the left if i'm not wrong :-) you better check this, i might mix up left and right.

then check the sign of the scalar product $\left(s_{x},s_{y}\right)\cdot\left(x_{2}-x_{1},y_{2}-y_{1}\right)$. if it's bigger than $0$ $\left(x_{2},y_{2}\right)$ is on the left, otherwise it's on the right.

to explain a bit why:

  • note that $\left(x_{2}-x_{1},y_{2}-y_{1}\right)$ gives the relative position of your point to the line
  • the scalar product measures the degree of parallelity of some vectors. (it's closely related to the cosine function)