# Check point is between two points

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

"between" means this:

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

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...
• @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... Mar 6, 2014 at 12:42
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.