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,
, from a point
to a line whose equation is
A x+B y + C=0
is given by
and the horizontal distance,
, is given by
.
Approach
Construct a vertical (horizontal) line through the given point. Intersect the vertical (horizontal) line with the given line. The required distance,
(
), is the distance between
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]}
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
. The expressions given by Mathematica are equivalent to the desired results.
{Distance2D[p1,pv],Distance2D[p1,ph]}
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
. 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]