Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Views: 152

Plotting lines and planes in 3D

Source: Many of the ideas and strategies in this worksheet are taken from the excellent resource on doing multivariate calculus in Sage by Prof. Sang-gu Lee, Mathematics Department, Sungkyunkwan University, Korea. The multivariate part of their Sage woksheets can be found at http://matrix.skku.ac.kr/Cal-Book/part2/part2.html.

In this module we will learn how to plot lines, planes and surfaces in 3D. The three basic sage functions we will use most frequently for 3D plotting are:

  • plot3d()
  • implicit_plot3d()
  • parametric_plot()

Run the builtin help on each of these functions to see the extensive range of features and options they offer:

    plot3d?
    implicit_plot3d?
    parametric_plot?

 

This module assumes you know how to define and work with vectors.

If not, please review/complete that module first.
Example 1: Find and plot each of the following as instructed:

  1. The line passing through the point (2,0,1)(2,0,1) and parallel to the vector i+jk{\bf i} + {\bf j} - {\bf k}.
    Show the line and the parallel vector in your plot.
  2. The line passing through the points (2,0,1)(2,0,1) and (0,2,0)(0,2,0)
  3. The plane passing through the point (2,0,1)(2,0,1) and perpendicular to the vector ijk-{\bf i} - {\bf j} - {\bf k}.
  4. Show the vector and the plane in your plot.
  5. The line of intersection of the planes 3x+2y+z=33x+2y+z=3 and x2y+3z=1x-2y+3z=1.
  6. Show the planes and the line of intersection in your plot.

# Example 1a: The line passing through the point (2,0,1) and # parallel to the vector i+j-k: t = var('t') r0 = vector( [2,0,1] ) # position vector of given point v = vector( [1,1,-1] ) # the parallel vector r = r0 + t*v # the answer, i.e., line through r0 and parallel to v print r myline = parametric_plot(r, (t,-4,4), color='green', thickness=3) myvec = plot(v, thickness=3) show(myline + myvec)
(t + 2, t, -t + 1)
3D rendering not yet implemented
# Example 1b: The line passing through the points (2,0,1) and # (0,2,0): t = var('t') r0 = vector( [2,0,1] ) # position vector of 1st point r2 = vector( [0,2,0] ) # position vector of 2nd point v = r2-r0 # vector from point 1 to point 2 r = r0 + t*v # the answer, i.e., line through r0 and parallel to v print r myline = parametric_plot(r, (t,-4,4), color='green', thickness=3) myvec = plot(v, thickness=3) show(myline + myvec)
(-2*t + 2, 2*t, -t + 1)
3D rendering not yet implemented
# Example 1c: The plane passing through the point (2,0,1) and # perpendicular to the vector -i-j-k: x, y, z = var('x, y, z') r = vector( [x, y, z] ) # Define a vector with variable components. r0 = vector( [2,0,1] ) # Position vector of given point. np = vector( [-1,-1,-1] ) # Given normal vector. # It is known from theory that if the normal vector is # np = <a,b,c>, then the plane looks like: a*x + b*y + c*z + d = 0 myplane = np.dot_product(r-r0) # This uses the fact that we can dot the # normal vector with vector (r-r0) to # get the LHS of the same plane. print 'The plane is:', myplane, '= 0' print ' ' p = implicit_plot3d(myplane == 0, (x,-5,5), (y,-5,5), (z,-5,5), color='green' ) q = plot(np, thickness=3) show(p+q)
The plane is: -x - y - z + 3 = 0
3D rendering not yet implemented
# Example 1d: The line of intersection of the planes 3x+2y+z=3 and # x-2y+3z=1. # Method 1: A short-cut that Sage makes easy to implement. # Step 1: Solve simultaneously the equations of the two planes # for x, y, z. # Step 2: Since there are 2 equations and 3 variables, Sage will # provide the solution in parametric form. Well, that parametric # form is, in fact, the line of intersection we want! x, y, z, t = var('x, y, z, t') myans = solve( [3*x+2*y+z==3, x-2*y+3*z==1], (x,y,z), solution_dict=True ) xsol = myans[0][x]; ysol = myans[0][y]; zsol = myans[0][z] print 'x =', xsol, ', y =', ysol, ', z =', zsol pp = implicit_plot3d(3*x+2*y+z==3, (x,-5,5), (y,-5,5), (z,-5,5), color='green' ) qp = implicit_plot3d(x-2*y+3*z==1, (x,-5,5), (y,-5,5), (z,-5,5), color='blue' )
x = -r22 + 1 , y = r22 , z = r22
rp = parametric_plot( (1-t, t, t), (t,-5,5), color='yellow', thickness=5) show(pp+qp+rp)
3D rendering not yet implemented
Exercise 1: Do these problems from Sec.9.5 of our textbook:

5, 23, 45.

In all cases, use Sage to do your computations and to graph your results.

Plotting other simple surfaces in 3D

We conclude with a brief glimpse of plotting more general surfaces in 3D.

Example 2: Plot each of the following as instructed:

  1. The equation y=x2+1y=-x^2+1 in R2\mathbb{R^2}, and then in R3\mathbb{R^3} (on separate plots, please!).
  2. Graph the surface x2+3z2=4x^2+3z^2=4 and describe what it looks like
  3. Graph the surface xyz=3xyz=3.
  4. show graphically that the curve of intersection of the surfaces x2+2y2z2+3x=1x^2+2y^2-z^2+3x = 1 and 2x2+4y22z25y==02x^2+4y^2-2z^2-5y == 0 lies in a plane.

# Example 2a: The equation y=-x^2+1 in R^2 and then in R^3. # Here is the plot in in R^2 plot(-x^2+1, (x,-4,4), axes_labels=['$x$', '$-x^2+1$'], color='green', thickness=3) # And here it is in R^3 implicit_plot3d(y == -x^2+1, (x,-5,5), (y,-5,5), (z,-5,5), color='green' )
3D rendering not yet implemented
# Example 2b: Graph the surface x^2+3z^2=4 and describe # what it looks like: implicit_plot3d(x^2+3*z^2 == 4, (x,-5,5), (y,-5,5), (z,-5,5), color='blue' )
3D rendering not yet implemented
Example 2b: continued

By rotating the 3D plot above, it looks like an elliptic cylinder, with center along the yy-axis.

# Example 2c: Graph the surface xyz=3: implicit_plot3d(x*y*z == 3, (x,-5,5), (y,-5,5), (z,-5,5), color='purple' )
3D rendering not yet implemented
# Example 2d: s1 = implicit_plot3d(x^2+2*y^2-z^2+3*x == 1, (x,-5,5), (y,-5,5), (z,-5,5), color='purple' ) s2 = implicit_plot3d(2*x^2+4*y^2-2*z^2-5*y == 0, (x,-5,5), (y,-5,5), (z,-5,5), color='green' ) show(s1+s2)
3D rendering not yet implemented
Exercise 2: Do these problems from Sec.9.6 of our textbook:

15(f), 23, 31.

Here is an extra exercise: Graph the following surface and determine what it looks like


(x2+(9/4)y2+z21)3x2z3(9/80)y2z3=0(x^2+(9/4)y^2+z^2-1)^3 -x^2z^3 - (9/80)y^2 z^3 = 0,     on x,y,z[1.5,1.5]x, y, z \in [-1.5,1.5], with red color.