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

$\begingroup$

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?

$\endgroup$ 2

7 Answers

$\begingroup$

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}$$

$\endgroup$ 4 $\begingroup$

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$$

$\endgroup$ 3 $\begingroup$

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.

$\endgroup$ $\begingroup$

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.$$

$\endgroup$ 1 $\begingroup$

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.

$\endgroup$ $\begingroup$

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)

$\endgroup$ $\begingroup$

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

$\endgroup$

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like