# How to find if the points fall in a straight line or not?

Three points $(x_1,y_1), (x_2,y_2)$ and $(x_3,y_3)$ whether fall in a straight line or not. How do I do that?

• You take two of the points, assuming they are different, you can find the equation that defines the only line that crosses them and then you just need to check if the third point satisfies the equation. – Git Gud Mar 6 '14 at 16:14
• Another way is to sum the distance between the two adjacent points, and see that if it equal to the distance between extreme points. – Sawarnik Mar 6 '14 at 16:51

## 7 Answers

if slopes of lines with any two point will be same , then they are co-linear

i.e. $$\frac{y_2-y_1}{x_2-x_1}=\frac{y_3-y_1}{x_3-x_1}$$

• How do you use this equation if any of the xs cancel out to 0, resulting in diving by 0? – Mirror318 Aug 2 '17 at 0:42
• If a pair of x's cancel out, that means those two points are part of a vertical line (same x values, different y values) – lfalin Oct 13 '17 at 15:11

Another way: a certain cross product must be zero, or $$\left( (x_2-x_1)\hat{i}+(y_2-y_1)\hat{j}\right) \times \left((x_3-x_1) \hat{i}+(y_3-y_1)\hat{j}\right)=\vec{0}$$

$$\implies (x_2-x_1)(y_3-y_1)-(y_2-y_1)(x_3-x_1) = 0$$

• -1. Have you ever checked your formula ? For $(x_3,y_3)=(2,2),(x_2,y_2)=(1,1),(x_1,y_1)=(0,0)$, which are on a line, your formular is false. I'm surprised no one ever remarked on this. – user10324 May 19 '16 at 16:12
• @user10324 Obviously it must be the cross product. Edited. – Macavity May 19 '16 at 16:36
• Ok, I removed the -1, due to your fast correction. (But it is not that obvious that it must be the cross product, if you're not fluent with analytic geometry!) – user10324 May 20 '16 at 5:01

Any two points are collinear in the cartesian plane and form an equation of the form $ax+by=c$. Simply test any two distinct pairs of numbers, find the associate $a$ and $b$, and see if they are the same.

Translate the points to $(0,0)$, $(x_2-x_1,y_2-y_1)$, $(x_3-x_1,y_3-y_1)$. Now, the condition is equivalent to the linear dependence of $(x_2-x_1,y_2-y_1)$, $(x_3-x_1,y_3-y_1)$, i.e.: $$\left|\matrix{x_2-x_1&y_2-y_1\cr x_3-x_1&y_3-y_1}\right| = 0.$$

• An equivalent, nicely memorable formulation would be $\begin{vmatrix}1&x_1&y_1\\1&x_2&y_2\\1&x_3&y_3\end{vmatrix}=0$. – ccorn May 19 '16 at 20:10

This answer is about approximate collinearity, and can be used when the coordinates are not exact (floating-point).

The angle between the line segments $12$ and $23$ is given by

$$\arctan\frac{y_2-y_1}{x_2-x_1}-\arctan\frac{y_3-y_2}{x_3-x_2}.$$

To compare this angle to a small tolerance $\delta$, we cancompare the tangents, like

$$\left|\tan\left(\arctan\frac{y_2-y_1}{x_2-x_1}-\arctan\frac{y_3-y_2}{x_3-x_2}\right)\right|\le\tan(\delta).$$

This can be rewritten as

$$\left|(y_2-y_1)(x_3-x_2)-(y_3-y_2)(x_2-x_1)\right|\le\\ \left|((x_2-x_1)(x_3-x_2)+(y_2-y_1)(y_3-y_2))\right|\tan(\delta).$$

On the left, you recognize a cross product (double area of the triangle) and on the right a dot product (giving a relative area information).

Obviously, with $\delta=0$, you find the same expression as in the other posts.

The easiest way to do it is to find out if y2-y1/x2-x1 y3-y1/x3-x1 are equal (The slope of points 1 and 2 vs the slope of points 1 and 3)

Equation of a straight line is a linear function ($y=ax+b$) now if the system $$y_1=ax_1+b\\y_2=ax_2+b\\y_3=ax_3+b$$ has solutions it works,otherwise not