Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

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|improve this question
add comment

4 Answers 4

up vote 2 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|improve this answer
add comment

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|improve this answer
add comment

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|improve this answer
add comment

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|improve this answer
add comment

Your Answer

 
discard

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.