Calculate if a point lies above or below (or right to left) of a line If you are given two points $A$ and $B$ which both have $x,y$ values in $\mathbb{R^2}$. These points join to make a line.
You are then given a third point $P$, also in $\mathbb{R^2}$.
You are then asked to calculate whether $P$ sits above or below the line created by joining $A$ and $B$.
I have been researching this question over the past few days and it seemed that everyone was suggesting the solution of using the two vectors $\vec{AB}$ and $\vec{AP}$. You then calculate the determinant of these vectors as follows:
$$(B_x-A_x)(P_y-A_y)-(B_y-A_y)(P_x-A_x)$$
As far as I am aware this actually calculates the area of a triangle that is created by joning the three points (and extending the sides to meet).
If the answer is $0$ it means that $P$ is sitting on the line $\vec{AB}$. If the value is positive, it sits on one side of the line, if it is negative it sits on the other side of the line.
To find out what side of the line, you then create another point that you know is above or below the line (e.g. A(x, y+1) would sit above the line). You can then use the above equation again and find out if being above the line results in a positive or negative value and use that to figure out where $P$ sits.
This is great and all, but this question is going to be asked in an interview, and although I have studied it I think the reasoning behind this logic is a bit over my head to explain.
That is when I asked a friend how they would solve the same question.
They said that they would calculate the line equation from the two points (AB) into the format $y = mx + b$
You could then substitute the value $x$ into the equation, and rearrange the equation to find out what $y$ would need to be in order for $P$ to lie on the line (make the line equation = 0). If the $y$ value needs to be decreased it would mean that the point is above the line, if the $y$ value needs to increase that means that the point is below the line.
I understand the second solution a lot more in my own head, but I am a bit worried that it was not suggested as a solution in any of the threads I was looking at, and maybe I am overlooking something?
I appreciate any feedback or advice regarding this.
 A: Here is the equation of a line in the 2D plane:
$$Y=MX+B$$
where $M$, the slope, is either a positive or a negative value. Because of this, you know the "slant" of the line as it goes from left to right.
For an arbitrary point not lying on the line, plug its $X$ value into your line equation. It will yield a corresponding $Y$ value. This is the $Y$ value of a point that lies on the line. Let's call that $Y_L$. Let's call the $Y$ value of your arbitrary point $Y_P$. Take the difference between the two:
$$Y_L-Y_P=\Delta{Y}$$


*

*If $\Delta{Y}$ is positive and $M$ is positive, your point lies below and to the right of the line.

*If $\Delta{Y}$ is positive and $M$ is negative, your point lies below and to the left of the line.

*If $\Delta{Y}$ is negative and $M$ is positive, your point lies above and to the left of the line.

*If $\Delta{Y}$ is negative and $M$ is negative, your point lies above and to the right of the line.


Think about this a little to see if it makes sense. Draw it on paper if you have to.
A: See, first you write your equation in $ax+by+c=0$ form.Next,let $f(x,y)=ax+by+c$,now put $(x,y)=(0,0) \implies f(0,0)=c$(Doesn't it?).Now suppose you have to find $(a,b)$ lies above or below(origin side or non-origin side).For the same,find $f(a,b) $,if sign(+ve or -ve) of $f(a,b)$ is same as that of $f(0,0)$,it means the point $(a,b)$ lies in origin side(Now,I hope you can verify if it's above the line or below the line ).If sign of $f(0,0) $ is not same as that of $f(a,b)$ then $(a,b)$ lies in non-origin side.
PS:A line divides the Cartesian plane into two planes .By Origin side ,I mean- The plane containing origin .
A: I think your confusion begins here:

If the answer is $0$ it means that $P$ is sitting on the line $\vec{AB}$. If the value is positive, it sits on one side of the line, if it is negative it sits on the other side of the line.
To find out what side of the line, you then create another point that you know is above or below the line (e.g. A(x, y+1) would sit above the line). You can then use the above equation again and find out if being above the line results in a positive or negative value and use that to figure out where $P$ sits.

It might help if, instead, you thought of "left-of line" or "right-of line" instead of "above" or "below". In fact, if you look at the section on "Area of a Triangle" and then check how to implement "Testing Angle Direction", they include a way to find the "angle" of $\angle a b c$. This is identical to the determinant you provided, and can be used to figure out which side of the line, left or right, your point $P$ is. To be exact: if $cw(A, B, P) > 0$, then $P$ is to the left of the line.
With the analytic geometry approach of $y = mx + b$, you will correctly get whether the point lies above or below the line, but only if the line is not vertical. Prefer the computational geometry approach, i.e. the determinant approach. It is much more robust.
