# Check the side of a vector 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!

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)
• do you have any idea to convert this to c++ code Mar 14, 2014 at 8:36
• just plug in the definition for $s$ (and then $r$) in $\left(s_{x},s_{y}\right)\cdot\left(x_{2}-x_{1},y_{2}-y_{1}\right)$. and note that $\left(a_{1},b_{1}\right)\cdot\left(a_{2},b_{2}\right)=a_{1}a_{2}+b_{1}b_{2}$
– Max
Mar 14, 2014 at 8:40
• how to solve this (rx,ry):=(x3,y3)−(x1,y1) Mar 14, 2014 at 9:25
• $\left(x_{3},y_{3}\right)-\left(x_{1},y_{1}\right)=\left(x_{3}-x_{1},y_{3}-y_{1}\right)$
– Max
Mar 14, 2014 at 20:16