16
$\begingroup$

Points $(a,b)$, $(m,n)$, and $(x,y)$ are selected at random. What is the quickest/easiest way to tell if they are collinear? At first I thought it was a matter of comparing slopes but that doesn't appear to be enough.

$\endgroup$
4
  • $\begingroup$ Can you explain why comparing slopes does not appear to be enough? By definition, points are collinear if they all lie on the same line. In the plane, 3 points are collinear if and only if the slopes between them are all the same. Here, same means equal as numbers or undefined. $\endgroup$ – Kris Williams May 29 '13 at 18:08
  • $\begingroup$ They can have the same slopes but be located in different places $\endgroup$ – user78793 May 29 '13 at 18:09
  • $\begingroup$ find out equation of straight line using two points and then put 3rd point in it.if it satisfy they are colinear $\endgroup$ – iostream007 May 29 '13 at 18:11
  • 2
    $\begingroup$ @user78793 Call the points $P,Q,R$. If $PQ$ has the same slope as $QR$, then they can't be located in different places, since they share the same point $Q$. No matter which two pairs of points you select (for slope calculation), they will share a point in common. $\endgroup$ – Adriano May 29 '13 at 18:12
21
$\begingroup$

"At first I thought it was a matter of comparing slopes"... and you were right!

If the line segments AB and BC have the same slope, then A, B, C are necessarily collinear. Note that there are some corner cases having to do with whether B is the "middle" point or not (in which case the slopes will still be equal), and one having to do with vertical lines (where some formula you use to compute slope might divide by 0).

Putting all this together, the points $(a, b)$, $(m, n)$ and $(x, y)$ are collinear if and only if $$(n-b)(x-m) = (y-n)(m-a)$$ (comes from $\frac{n-b}{m-a} = \frac{y-n}{x-m}$, but not writing it in fraction form to avoid division by $0$).

$\endgroup$
2
  • $\begingroup$ @ronno: Thanks for pointing it out. Very bad of me; I hope it's right now... $\endgroup$ – ShreevatsaR May 29 '13 at 19:07
  • $\begingroup$ It is correct, and it agrees with $a(n−y)+m(y−b)+x(b−n)=0$. $\endgroup$ – Librecoin May 29 '13 at 19:21
18
$\begingroup$

The area is zero, in formula $\det \pmatrix{1 &a &b\\ 1 &m &n\\ 1 &x &y}=0$

$\endgroup$
3
  • $\begingroup$ How do you calculate det()? $\endgroup$ – user78793 May 29 '13 at 18:11
  • 2
    $\begingroup$ @user78793 Explicitly, the determinant here is $a(n-y)+m(y-b)+x(b-n)$. $\endgroup$ – Hagen von Eitzen May 29 '13 at 18:31
  • $\begingroup$ that was due to network error $\endgroup$ – iostream007 May 29 '13 at 18:33
5
$\begingroup$

This is an explanation of $\textbf{Ma Ming}$'s excellent idea, in case it was unclear.

Consider a triangle with vertices at points $(a,b)$, $(m,n)$, and $(x,y)$, and observe that the area $A$ of the triangle is zero if and only if the points are collinear. Now, it can be shown that

$$A=\frac{1}{2}\left|\det\pmatrix{1&1&1\\a&m&x\\b&n&y}\right|=\frac{1}{2}\left|a(n−y)+m(y−b)+x(b−n)\right|.$$

Hence we just have to check whether the expression $a(n−y)+m(y−b)+x(b−n)$ is non-zero or not.

$\endgroup$
1
$\begingroup$

Another way is to choose any two of the three points to construct a pair of parametric equations for the line they lie on, say,

$$X \ = \ a \ + \ (m - a) \cdot t \ , \ Y \ = \ b \ + \ (n - b) \cdot t \ , $$

with $ \ t \ $ being the parameter. For the third point, $ \ (x, y) \ $ , find the value of a parameter $ \ s \ $ which solves $ \ x \ = \ a \ + \ (m - a) \cdot s \ $ . If the same value $ \ s \ $ produces an equation for $ \ y \ = \ b \ + \ (n - b) \cdot s \ , $ then the three points are collinear; otherwise... they aren't!

This approach can be extended without much difficulty to deal with the reference line being horizontal or vertical (so there is no complication with things like undefined slopes).

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.