I want to check whether $(x_3,y_3)$ is between $(x_1,y_1)$ and $(x_2,y_2)$.

"between" means this:

enter image description here

  • $\begingroup$ What did you try ? What is the second figure for ? $\endgroup$ Mar 6, 2014 at 11:03
  • $\begingroup$ the point should be in between these two lines. I want to check that. $\endgroup$ Mar 6, 2014 at 11:05
  • $\begingroup$ That depends on the lengths of those thin lines, what are they? Are they the same? $\endgroup$
    – flonk
    Mar 6, 2014 at 11:16
  • 1
    $\begingroup$ The angles $\widehat{A_3A_1A_2}$ and $\widehat{A_3A_2A_1}$ should be acute. $\endgroup$
    – user5402
    Mar 6, 2014 at 21:41

2 Answers 2


If $\exists t$, such that $$ \pmatrix{x_2-x_1\\y_2-y_1}t + \pmatrix{x_1\\y_1}=\pmatrix{x_3\\y_3}, $$ then $\pmatrix{x_3\\y_3}$ lies between the two others..


Complete the triangle. If the angles at $\pmatrix{x_2\\y_2}$ or $\pmatrix{x_1\\y_1}$ are both less than $90^\circ$ then $\pmatrix{x_3\\y_3}$ is between. See here how to calculate the angles...

  • $\begingroup$ what is this "t" means $\endgroup$ Mar 6, 2014 at 11:50
  • $\begingroup$ @JanithOCoder just a parameter: if there is a value for $t$, then you know that the third point lies directly on the line between the first and the second point, but only the stuff after EDIT seems to be relevant for you... $\endgroup$
    – draks ...
    Mar 6, 2014 at 12:42

Drop the perpendicular from point 3 on the line between point 1 and point 2, and see where the foot point of this perpendicular is.

That is, compute the difference between the endpoints of the line $$ d_0 = \pmatrix{x_2-x_1\\y_2-y_1} $$ and its direction $$ v = d_0 / ||d_0|| $$ Then compute the vector from the start point of the line to the point in question $$ d_1 = \pmatrix{x_3-x_1\\y_3-y_1} $$ And finally, the dot product $$ r = v * d_1 $$ When this dot product is in the range $[0, ||d_0||]$, then the point is between the other points.


You must log in to answer this question.

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