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 Answer 1


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)
  • $\begingroup$ do you have any idea to convert this to c++ code $\endgroup$ Mar 14, 2014 at 8:36
  • $\begingroup$ 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}$ $\endgroup$
    – Max
    Mar 14, 2014 at 8:40
  • $\begingroup$ how to solve this (rx,ry):=(x3,y3)−(x1,y1) $\endgroup$ Mar 14, 2014 at 9:25
  • $\begingroup$ $\left(x_{3},y_{3}\right)-\left(x_{1},y_{1}\right)=\left(x_{3}-x_{1},y_{3}-y_{1}\right)$ $\endgroup$
    – Max
    Mar 14, 2014 at 20:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .