Using Vectors to Represent Lines and Find Distances

Introduction

OBJECTIVE:  Visualize and interpret the use of vectors to represent lines in the plane.

Do you remember how you first learned about the equations of lines in a plane? In this module, you will gain insight into why it is to your advantage to interpret lines in the plane using vectors.

Technology Guidelines

NOTE:  If you have just finished a module, restart Mathematica or Quit Kernel under the Evaluation pull-down menu before executing a new module.
TO OPEN CELLS, click on the arrow to the left of the cell or put your cursor on the right cell bracket and double click. To open all cells, highlight the bracket on the far right and select Grouping under the Cell pull-down menu and select Open All Subgroups.
TO STOP AN EXECUTION
Select the Evaluation pull-down menu and click on Abort Evaluation.
ORDER OF EXECUTION
Execute cells in the order given. Do not skip any Input cells within a given notebook.
SAVING NOTEBOOKS
You can save anytime to any directory you choose, and it is wise to save often. However, before you do your final save to reduce the size of your file, it is a good idea to delete all your output by selecting the Delete All Output selection under the Cell pull-down menu.
EXPERIENCING MAJOR PROBLEMS
Save if appropriate, then shut down Mathematica and start it up again.

Part I:  Interpreting Lines Using Their Vector Definition

You can construct straight lines in two dimensions using the vector definition. Given two points on the line, you will first determine the direction of the line and then write any other point on the line as the position vector to that point plus a multiple (t) of the vector in the direction of the line.  We plot points along the line corresponding to different values of the parameter t. Our example uses points (1,5) and (4,2) and we plot points for values of t from -10 to 10.

Clear[x,y,t]
origin={0,0};
p1={1,5};
p2={4,2};
Print["The direction of the line is ",dir=p1-p2]
Print["{x,y} = ",eq=(p1-origin)+t dir]
ParametricPlot[Evaluate[eq],{t,-10,10},AxesLabel->{x,y}]

You Try It - Part I

Write and plot the line connecting the points (-23, -5) and (10, 12) in parametric form.
You need to identify and enter the new points for p1 and p2 on the line and re-execute the input cell. Simply replace the numbers in red.

origin={0,0};
p1={1,1};p2={2,2};Print["The direction of the line is ",dir=p1-p2]
Print["{x,y} = ",eq=(p1-origin)+t dir]
plot1=ParametricPlot[Evaluate[eq],{t,-10,10},AxesLabel->{x,y}]

For the preceding function, match the parametric plot with the standard Cartesian form and plot. You need to solve for y as a function of x and put that into the expression for f[x_]. Replace the expression in red with the appropriate expression.

f[x_]:=x
pf=Plot[f[x],{x,-10,10},PlotStyle->RGBColor[1,0,0],AxesLabel->{"x","y"}]
Show[plot1,pf]

Part II:  Different Parametric Forms for the Same Line

Write the equation of the line y = 3x - 5 in parametric form. 
You may be accustomed to seeing equations of lines in the standard slope intercept form. That form is a unique representation. In contrast, the parametric form can appear in different forms; however, the set of points represented is the same.

If we take the direction vector from the slope to be (1,3) and use the y-intercept (0,5) as our given point on the line, we get the following.

Clear[x,f]
origin={0,0};
dir={1,3};
p1={0,-5};
Print["{x,y} = ",eq=(p1-origin)+t dir]
plot1=ParametricPlot[Evaluate[eq],{t,-3,5},AxesLabel->{x,y},AspectRatio->1,PlotStyle->RGBColor[0,1,0]]

Had we used a different point on the line, for example, (2,1), and written the slope as (2, 6), the equation would look a bit different, although it would produce the same line.

Clear[x,f]
dir={2,6};
p2={2,1};
Print["{x,y} = ",eq=(p2-origin)+t dir]
plot2=ParametricPlot[Evaluate[eq],{t,-1,3},AxesLabel->{x,y},AspectRatio->1,PlotStyle->RGBColor[0,0,1]]

We can look at these graphs together.

Show[plot1,plot2]

Note that the parameter t is not the same in the two equations. However, all the points lie on the same line, even though we are plotting only segments of that line.

 For the preceding function, match the parametric plot with the standard Cartesian form and plot.

f[x_]:=3 x-5
pf=Plot[f[x],{x,-1,5},PlotStyle->RGBColor[1,0,0],AxesLabel->{"x","y"}]
Show[plot1,plot2,pf]

Do they match?

You Try It - Part II

Write the line 4x + 5y = 12 in parametric form. 
You need to identify a point on the line and a vector in the direction of the line. Substitute these for dir and p1 (items in red), and re-execute the input cell.

dir={1,2};
p1={1,1};Print["{x,y} = ",eq=(p1-origin)+t dir]
plot1=ParametricPlot[Evaluate[eq],{t,-3,5},AxesLabel->{x,y},AspectRatio->1,PlotStyle->RGBColor[0,1,0]]

For the preceding function, match the parametric plot with the standard Cartesian form and plot. 
You need to solve for y as a function of x and put that into the expression for f[x_]. Replace the red with the appropriate expression.

f[x_]:=2 x-1
pf=Plot[f[x],{x,-1,5},PlotStyle->RGBColor[1,0,0],AxesLabel->{"x","y"}]
Show[plot1,pf]

Part III:  Finding the Distance from a Point to a Line

Suppose you are driving on a long, straight road on a flat planar region of desert land. You have a grid-map of the region and have been told that there is a radiation site in the at the point (230, -500). You started at the point (-400, 350) and are traveling in a path that is always in the direction of the vector (1, -2). You are worried about how close to the radiation site you will pass.

Let's begin by visualizing the problem.

origin={0,0};
site={230,-500};
start={-400,350};
dir={1,-2};
Print["{x,y} = ",eq=(start-origin)+t dir]
pp=ParametricPlot[Evaluate[eq],{t,0,700},AxesLabel->{x,y},AspectRatio->1,DisplayFunction->Identity];
rad=ListPlot[{site},PlotStyle->PointSize[0.02`],DisplayFunction->Identity];
Show[pp,rad,DisplayFunction->$DisplayFunction]

Consider the vector from the starting point to the radiation site.

vector=site-start;
vp=ListPlot[{start,site},Joined->True,DisplayFunction->Identity];
Show[pp,rad,vp,DisplayFunction->$DisplayFunction]

Now, use the dot product to find the projection of this vector onto a direction perpendicular to the line. That will represent the shortest distance between the radiation site and the road.

Finding the perpendicular to a vector in two-space is very easy. Think of how perpendicular lines have slopes that are negative reciprocals of each other. You will find the perpendicular to the line by simply reversing the x and y components of the direction vector and negating one of them.

perpdir={-dir[[2]],dir[[1]]}

Then to find the projection of the vector connecting the starting point with the radiation site onto this perpendicular direction, use the dot product of those two vectors and divide by the magnitude of the perpendicular vector.

distance=Abs[vector.perpdir]/(Sqrt[perpdir.perpdir])//N

You Try It - Part III

Find the shortest distance from the line 4x + 5y = 12 to the point (-2,3).
In the following set of commands, put in the new site, select a point on the line, and identify the direction of the line. To do this, just replace the red with the appropriate expressions.

origin={0,0};site={1,1};start={2,2};dir={-3,3};Print["{x,y} = ",eq=(start-origin)+t dir]
pp=ParametricPlot[Evaluate[eq],{t,-10,10},AxesLabel->{x,y},AspectRatio->1,DisplayFunction->Identity];
rad=ListPlot[{site},PlotStyle->PointSize[0.02`],DisplayFunction->Identity];
Show[pp,rad,DisplayFunction->$DisplayFunction]
vector=site-start;
perpdir={-dir[[2]],dir[[1]]};
distance=N[((Abs[vector.perpdir])/(Sqrt[perpdir.perpdir]))];
Print["The shortest distance from the point to the line is ",distance]