play and relax: games for kids games
  Cut the knot: learn to enjoy mathematics
A math books store at a unique math study site. Learn to enjoy mathematics.
Google
Web CTK
Best sites for teachers
Sites for teachers
Sites for parents
Terms of use
Awards

Interactive Activities
CTK Exchange
CTK Insights - a blog

Games & Puzzles
What Is What
Arithmetic/Algebra
Geometry
Probability
Outline Mathematics
Make an Identity
Book Reviews
Eye Opener
Analog Gadgets
Inventor's Paradox
Did you know?...
Proofs
Math as Language
Things Impossible
Visual Illusions
My Logo
Math Poll
Cut The Knot!
MSET99 Talk
Other Math sites
Front Page
Movie shortcuts
Personal info
Privacy Policy

Guest book
News sites

Recommend this site

Best sites for teachers
Sites for teachers
Sites for parents

Education & Parenting

Manifesto: what CTK is about Search CTK Buying a book is a commitment to learning Table of content Things you can find on CTK Chronology of updates Email to Cut The Knot Recommend this page

Distance From a Point to a Straight Line

On this page we'll derive an engaging formula for the distance from a point to a straight line. If a line L is given by its general equation

(1) Ax + By + C = 0

and a point P = (u, v) is given in the plane, then the distance dist(P, L) from the point to the line is determined by

(2) dist(P, L) = |Au + Bv + C| / ||n||,

where n = (A, B) is the vector of the coefficients, normal to the line. ||n|| is the norm of the vector. If the equation is normalized, i.e., if A2 + B2 = 1, (2) is simplified:

(2') dist(P, L) = |Au + Bv + C|.

To see why this is so, observe that (1) tells us that a straight line is a level curve f(x, y) = 0 of a (linear) function

(3) f(x, y) = Ax + By + C.

(For any function f of any number of arguments, a level surface is the locus of points where f takes on the same value f = c, say. For functions of two arguments, the locii are naturally called level curves.)

For the function (3), the level curves

  Ax + By + C = c

are all straight lines parallel to the one given by (1) because all of them are perpendicular to the same normal vector n = (A, B).

(In the applet below, a straight line is defined by two points, each of which can be dragged independently causing a rotation around the other point. The line can also be dragged parallel to itself at any other point. There is an additional point with the distance to the line indicated in blue. The point can also be dragged. Note: the applet gives you a precision of 0 to 6 digits. The equalities therefore are not quite exact.)


This applet requires Sun's Java VM 2 which your browser may perceive as a popup. Which it is not. If you want to see the applet work, visit Sun's website at http://www.java.com/en/download/index.jsp, download and install Java VM and enjoy the applet.


Buy this applet
What if applet does not run?

The distance from a point to a line (or to any set, for that matter) is defined as the minimum distance between the given point and the points on the line:

  dist(P, L) = min(dist(P, r)),

over all r = (x, y) belong to line L. The minimum always exists for a straight line, but may not exist for other sets. For a straight line, the minimum is achieved at the foot of the perpendicular from the given point to the line. It is noteworthy that all points on one of the level lines have the same distance to any other level line, because the lines are parallel and the distances are measured via the perpendiculars. This is how the normal to the line comes into the play.

The function does not change its value along the level lines. All the change comes along the direction of the normal n = (A, B)! Assume m = n/||n|| is the unit vector normal to the level lines of the given function:

  m = (A/||n||, B/||n||).

Pick a point (x0, y0) and define (x1, y1) = (x0, y0) + m. What is the difference between f(x1, y1) and f(x0, y0)? Since the function f is linear we have

 
f(x1, y1) - f(x0, y0)= (Ax1 + By1 + C) - (Ax0 + By0 + C)
 = A·A/||n|| + B·B/||n||
 = A2/||n|| + B2/||n||
 = (A2 + B2)/||n||
 = ||n||2/ ||n||
 = ||n||.

That is, every step by one unit in the direction normal to the line change the value of the function by the norm of its normal vector? This is true for any linear function and for any form of its equation. In particular, if the equation is normalized to start with, a unit step in the direction normal to the line changes its value by exactly 1!. With every unit step, the values on the level lines grow by 1 in the direction of the normal, but they decrease by 1 in the opposite direction. The line (1) divides the plane into two halves. In one, which is pointed to by the normal n = (A, B), f takes on positive values; in the other f is negative throughout.

Once this simple behavior has been observed, let d = dist(P, L).

Define now

(4) (x, y) = (u, v) - d(±m).

where we choose the sign "+" if P lies in the "positive half-plane". We choose "-" otherwise. Since d is the distance from P = (u, v) to the line, and the distance from a point to the line is measured along the normal, i.e. m, the point (x, y) in (4) lies on the line: f(x, y) = 0. This entails a sequence of steps:

 
0= f(x, y)
 = A(u - d·(±A/||n||)) + B(v - d·(±B/||n||)) + C
 = (Au + Bv + C) - d·[±(A2/||n|| + B2/||n||)]
 = f(u, v) - [±d||n||].

In other words,

(5) d = ± f(u, v) / ||n||,

where the sign is chosen so as to make ± f(u, v) positive. If d is considered the signed distance, i.e., if d comes with a sign minus if f(u, v) is negative, the formula is simplified to

(5') d = f(u, v) / ||n||.

In any event, we can conclude that (2) is indeed true.

If a straight line is given by an implicit equation n·(r - r0) = 0, we can similarly set

  f(r) = n·(r - r0)

for r not necessarily on the line. Then the distance d from a point P to the line can be found from

  d = | n·(P - r0)| / ||n|| = | f(P)/||n|| |.

Copyright © 1996-2008 Alexander Bogomolny

29397671Page copy protected against web site content infringement by Copyscape


Search:
Keywords:


Latest on CTK Exchange
try this puzzle ?/?? + ?/?? + ?/? ...
Posted by albert1950
0 messages
07:05 AM, Jul-10-08

Monty Hall Problem
Posted by linkdon
71 messages
03:06 PM, Jul-18-08

Missing information
Posted by roboknight
2 messages
07:32 AM, Jun-22-08

Golden Number linked to 666
Posted by Titus
4 messages
02:53 PM, Jul-19-08

Mistake on the page (an aside, Be ...
Posted by Max
4 messages
10:28 AM, Feb-28-08

trisection of an angle
Posted by Pytheus
2 messages
06:39 AM, Jul-14-08

You can drill a square hole
Posted by Giorgis
1 messages
10:15 PM, Jul-12-08