Lines

What is the slope-intercept form of a line?

The slope-intercept form of a line is:

	y = mx + b

Where the slope, m, is given by:

	m = (y2 - y1)/(x2 - x1)
	m = rise/run
The y-intercept, b, is the y-coordinate from the point at which the line intersects the y-axis: (0,b).

How can I find the slope of a line?

If you know two points on the line, (x1, y1) and (x2, y2):
	m = (y2 - y1)/(x2 - x1)
If you have a equation for the line:
Manipulate the equation until it is in slope-intercept form. The slope is the coeffecient of x.

How can I find the y-intercept of a line?

If you know the slope and one point on the line, (x,y):
	b = y - mx
If you know two points on the line:
Find the slope and use the above method to find the y-intercept.
If you have an equation for the line:
Manipulate the equation until it is in slope-intercept form. The y-intercept is the constant.

What is the parametric form of a line?

Given points P1 = (x1,y1) and P2 = (x2,y2), the parametric form for the line is:

	x = x1 + t(x2-x1)
	y = y1 + t(y2-y1)
	0 <= t <= 1
Note that t is the same in both equations. t is called the parameter. When t = 0 we get P1 and when t = 1 we get P2. As t varies between 0 and 1, we get all the other points on the line segment between P1 and P2.

Because the slope of a vertical line is infinite, the slope-intercept form of a line can be troublesome to work with. Since the parametric form does not involve slope, vertical lines are no longer a special case.

What is the parametric form of a line in 3D?

Given points P1 = (x1,y1,z1) and P2 = (x2,y2,z2), the parametric form for the line is:

	x = x1 + t(x2-x1)
	y = y1 + t(y2-y1)
	z = z1 + t(z2-z1)
	0 <= t <= 1
Or more compactly:

	L=P1 + t(P2-P1)
	0 <= t <= 1
Given a point P1 and a vector V = [xv,yv,zv]:

	x = x1 + t(xv)
	y = y1 + t(yv)
	z = z1 + t(zv)
	0 <= t <= 1

What is the difference between a line and a line segment?

A line is infinite: it has no beginning or end. A line segment is a piece of a line: it has a beginning point and and ending point. Both, however, contain an infinite number of points.

How do I find the distance between 2 points?

The distance between two points (x1,y1) and (x2,y2) is found by using the Pythagorean Theorem:

	D = sqrt((x2-x1)^2 + (y2-y1)^2)

How do I find the distance between a point and a line?

The distance, D, between a point and a line is the length of the perpendicular line segment connecting the point and the line.

To find D:

  1. Find the slope, m', of the line segment P1P2. (Since it is perpendicular to the other line, it is the inverse of its slope: 1/m.)
  2. Find the slope-intercept form of the line containing P1P2 using m' and P1.
  3. Find P2, the intersection of these two lines.
  4. Compute the distance between P1 and P2. This is the distance between P1 and the line, D.

How do I find the intersection of two lines?

For two lines, L1 and L2, we are looking for the point (x,y) that satisfies both equations:
  1. Put the equations into slope-intercept form:
    		y = m1*x + b1
    		y = m2*x + b2
    
  2. Set them equal to each other:
    		m1*x + b1 = m2*x + b2
    
  3. Solve for x:
    		x = (b2 - b1)/(m1 - m2)
    
  4. Substitute x back into one of the original equations to find y.
  5. The intersection is the point (x,y).
Note that parallel lines do not intersect and will cause a zero denominator in step 3.

To find the intersection of more than 2 lines, use a more general method for solving simultaneous equations, such as Gaussian Elimination.

How do I find the midpoint of a line segment?

The midpoint, M, of a line segment (x1,y1) to (x2,y2) is given by:

	M = (x,y) = ((x1+x2)/2, (y1+y2)/2) 

How can I tell if a point on a line is in a particular line segment?

For a line segment P1P2, P1 = (x1,y1) and P2 = (x2,y2), to determine if a point P3 = (x3,y3) is in the line segment:
  1. Solving for t in the x (or y) equation of the parametric form:
    		t = (x - x1)/(x2 - x1)
    
  2. Let x = x3. Substitute for x, x1 and x2 to yield a value for t.
  3. If 0 <= t <= 1, then P3 is in the line segment P1P2.

What is a polyline?

A polyline is a sequence of lines connecting successive vertices.

How can I tell if two lines are perpendicular?

Two lines with slopes M1 and M2 are perpendicular if:

How can I tell if two lines are parallel?

Two lines with slopes M1 and M2 are parallel if: