Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I determine whether the 2 points $(a_x, a_y)$ and $(b_x, b_y)$ are on opposite sides of the line $(x_1,y_1)\to(x_2,y_2)$?

share|cite|improve this question
up vote 4 down vote accepted

Explicitly, they are on opposite sides iff $$((y_1-y_2)(a_x-x_1)+(x_2-x_1)(a_y-y_1))((y_1-y_2)(b_x-x_1)+(x_2-x_1)(b_y-y_1)) < 0.$$

share|cite|improve this answer
Appreciate the explicitness of your answer. Clearly I am no math geek :) Cheers! – Craig Day Jun 25 '12 at 7:42

Find the equation of the line. It should be of the form $ax + by + c = 0$. Given two points $(x_1, y_2)$ and $(x_2, y_2)$, plug these into that equation. They are on opposite side of the line if $ax_1 + by_1 + c < 0$ and $ax_2 + by_2 + c > 0$, or visa-versa.

share|cite|improve this answer

$CD$ are on the opposite sides of $AB$ if and only if $\left(\overrightarrow{AB}\times\overrightarrow{AC}\right)\cdot\left(\overrightarrow{AB}\times\overrightarrow{AD}\right)<0$, where $\times$ is cross product and $\cdot$ is dot product.

share|cite|improve this answer
How is the cross product defined for 2 dimensions? – marty cohen Dec 1 '15 at 0:44
@martycohen Defined for an arbitrary embedding $\mathbb R^2\hookrightarrow\mathbb R^3$. – Frank Science Dec 1 '15 at 9:35

Writing $A$ and $B$ for the points in question, and $P_1$ and $P_2$ for the points determining the line ...

Compute the "signed" areas of the $\triangle P_1 P_2 A$ and $\triangle P_1 P_2 B$ via the formula (equation 16 here) $$\frac{1}{2}\left|\begin{array}{ccc} x_1 & y_1 & 1 \\ x_2 & y_2 & 1 \\ x_3 & y_3 & 1 \end{array}\right|$$ with $(x_3,y_3)$ being $A$ or $B$. The points $A$ and $B$ will be on opposite sides of the line if the areas differ in sign, which indicates that the triangles are being traced-out in different directions (clockwise vs counterclockwise).

You can, of course, ignore the "$1/2$", as it has not affect the sign of the values. Be sure to keep the row-order consistent in the two computations, though.

share|cite|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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