Exploring Analyic Geometry with Mathematica®

Home Contents Commands Packages Explorations Reference
Tour Lines Circles Conics Analysis Tangents

Vertical/Horizontal Distance to a Line

lndist.html

Exploration

Show that the vertical distance, "lndist_1.gif", from a point "lndist_2.gif" to a line whose equation is

A x+B y + C=0

is given by

"lndist_3.gif"

and the horizontal distance, "lndist_4.gif", is given by

"lndist_5.gif".

Approach

Construct a vertical (horizontal) line through the given point. Intersect the vertical (horizontal) line with the given line. The required distance, "lndist_6.gif" ("lndist_7.gif"), is the distance between "lndist_8.gif" and the intersection point.

Initialize

To initialize Descarta2D, select the input cell bracket and press SHIFT-Enter.

This initialization assumes that the Descarta2D software has been copied into one of the standard directories for AddOns which are on the Mathematica search path, $Path.

<<Descarta2D`

Solution

Construct the vertical (horizontal) line through the given point.

Clear[x1,y1];
p1=Point2D[x1,y1];
{lv=Line2D[p1,Infinity], lh=Line2D[p1,0]}

"lndist_9.gif"

Intersect the vertical (horizontal) line with the given line.

Clear[a,b,c];
l1=Line2D[a,b,c];
{pv=Point2D[l1,lv],ph=Point2D[l1,lh]};

Find the distance between the intersection point and "lndist_10.gif". The expressions given by Mathematica are equivalent to the desired results.

{Distance2D[p1,pv],Distance2D[p1,ph]}

"lndist_11.gif"

Discussion

If the point is on the line, then both distances are clearly zero since the point satisfies the equation of the line. If the line has a slope of ±1 (A=±B), then "lndist_12.gif". If the given line is vertical (horizontal), then the vertical (horizontal) distance formula is invalid (i.e. A or B is zero).  Here's a function for vertical distance. The function for horizontal distance would be similar.

Distance2D[Point2D[{x1_,y1_}],
           Line2D[A2_,B2_,C2_],
           Vertical2D]:=
   Abs[(A2*x1+B2*y1+C2)/B2] /;
Not[IsZero2D[B2]]

This computes the vertical distance from (9,2) to the line 2x-4y-3=0.

Distance2D[Point2D[{9,2}],Line2D[2,-4,-3],Vertical2D]

"lndist_13.gif"


Copyright © 1999-2007 Donald L. Vossler, Descarta2D Publishing
www.Descarta2D.com