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

I asked this question on stackoverflow: enter image description here

$AB$ is the line, $C$ is the point.

In the accepted answer of the above question, if the difference in equation is $0$, then points are collinear, so in the above image, it proves it correct as theta is same, so far so good.

Then in the image below, $C$ lies on right of line :

enter image description here

the fi angle is less than theta so the difference is positive. So in my program if I take $> 0$ as condition for the point on right, then the difference should always be greater than $0$ if point is on right.

But my next figure shows that the even if the point is on right of the line, the difference can be negative :

enter image description here

In figure 3, even though the point is on right of the line, fi is greater than theta, so the diffrence is negative.

In accepted answer, if I take positive difference for point on right side, then the above case will give wrong results.

Where am I going wrong ?

share|cite|improve this question
Rather complicated, that. Do you know the formula for computing a directed point-line distance? Alternatively, if your line segment is represented by its two endpoints, you could use the determinantal formula for the signed area of a triangle. – J. M. Apr 3 '13 at 7:04
In the figure 2, your assumption of the angle $\phi$ is wrong. You should always take the angle the line makes with the x-axis in the anti-clockwise direction. Hence $\phi$ in that case would be 'obtuse angle' and hence the difference would turn out to be negative. – lsp Apr 3 '13 at 7:17
up vote 2 down vote accepted

J.M. has it -- compute the signed determinant area of the triangle ABC

  • If it's zero, the points are colinear
  • If it's +ve then C is on one side of the line (depending on which way you write down the determinant...)
  • If it's -ve then C is on the other side.
share|cite|improve this answer

according to figure 2, instead of checking: $$ \frac {Bx-Ax}{By-Ay} - \frac {Cx-Ax}{Cy-Ay} $$

You should check the angle from +ve x-axis (phi you are taking is measured from -ve x-axis): $$ \tan^{-1}( \frac {Ay-By}{Ax-Bx}) < abs (\tan^{-1}(\frac{Cy-Ay}{Cx-Ay})) $$ this will be true for both figures 2 and 3 and all points on the right side.

and the angle of CA w.r.t +ve x-axis would be less than angle of BA w.r.t. +ve x-axis, if C lies on the left hand side of the line.

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.