Jonathan Miles

2022-07-10

I have two points $\left(0,0\right)$ and $\left(93,3\right)$
I'm trying to work out whether a point is on or below the line segment defined by those two point.
Currently I'm using $Ax+By+C=0$ to see if a point is on or below this line segment and this works correctly except for when the point is of the form $\left(0,y\right)$ or $\left(x,0\right)$
What am I doing wrong? Do I need to use a different form of the linear equation?

Kroatujon3

Expert

For this particular example it would seem to be easier to write the equation for the line in slope-intercept form:
$y=\frac{1}{31}x+0$
Then given any $\left(x,y\right)$, you can test directly whether the point lies above or below the point on the line that has the same $x$ coordinate.

delirija7z

Expert

Suppose your given points are $\left({x}_{1},{y}_{1}\right)$ and $\left({x}_{2},{y}_{2}\right)$. First get the slope $m=\frac{{y}_{1}-{y}_{2}}{{x}_{1}-{x}_{2}}$. The equation of the line joining the points is $y-{y}_{1}=m\left(x-{x}_{1}\right)$, where you just substitute ${x}_{1},{y}_{1}$, and $m$. In slope intercept form the equation is
$y=mx+\left({y}_{1}-m{x}_{1}\right).$
Given a point $\left(p,q\right)$, first check that ${x}_{1}\le p\le {x}_{2}$. Then: $q>mp+\left({y}_{1}-m{x}_{1}\right)$ means the point is above the segment, and $q means the point is below the segment.
If you already have the equation of the line joining the points as $Ax+By+C=0$, then the equation of the line can be expressed as $y=-\frac{B}{A}x-\frac{C}{A}$, so just check to see whether $q>-\frac{B}{A}p-\frac{C}{A}$ or not.

Do you have a similar question?