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 have two points $(0,0)$ and $(93,3)$

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 $(0,y)$ or $(x,0)$

What am I doing wrong? Do I need to use a different form of the linear equation?

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

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 $(x,y)$, you can test directly whether the point lies above or below the point on the line that has the same $x$ coordinate.

share|cite|improve this answer

Suppose your given points are $(x_1,y_1)$ and $(x_2,y_2)$. 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(x-x_1)$, where you just substitute $x_1,y_1$, and $m$. In slope intercept form the equation is $$ y = mx + (y_1-mx_1). $$ Given a point $(p,q)$, first check that $x_1\le p\le x_2$. Then: $q > mp + (y_1-mx_1)$ means the point is above the segment, and $q< mp + (y_1-mx_1)$ 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.

share|cite|improve this answer

What you need is orientation test.

Here is a nice picture from Jonathan Richard Shewchuk: Adaptive Precision Floating-Point Arithmetic and Fast Robust Predicates for Computational Geometry, link:

In your case $(a_x, a_y) = (0, 0)$ and $(b_x, b_y) = (93, 3).$ Finally, $(c_x, c_y)$ are the coordinates of the test point. Evaluate the determinant, and the sign of the determinant indicates whether $c$ is to the {left, righ, or on} the line $ab.$

share|cite|improve this answer

Here is a solution:

A vector can be created connecting (0,0) and (93,3) called $\hat v$, Now take your point $P(x,y)$ which you need to analyze for location. Another vector can be created $\hat w = P - (0,0)$

Carry out $\hat v \times \hat w$, if the vector is positive, the w is to the left of the line else it is to the right.

Here is an example:

$$v = 93i+3j$$ $$w=10i$$ $$v\times w = -30k$$ Thus, this point (10,0) lies to the right of your 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.