# Computing which side of a line a point is

I asked this question on stackoverflow:

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

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 :

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 ?

-
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

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

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.

-