︠39e05a12-79bc-425a-b32d-dfc061ff429fi︠ %hide %html

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:

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

 

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

If not, please review/complete that module first.
︡7cf099db-4db6-4465-a753-bb4525ab9948︡{"hide":"input"}︡{"html":"

Plotting lines and planes in 3D

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

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

\n\n\n

\nRun the builtin help on each of these functions to see\nthe extensive range of features and options they offer:\n

\n\n\n

 

\n\nThis module assumes you know how to define and work with vectors.\n

\nIf not, please review/complete that module first.\n
"}︡{"done":true}︡ ︠ddc455d3-aba7-4b87-8f75-204dd4c5f0a8i︠ %hide %html Example 1: Find and plot each of the following as instructed:

  1. The line passing through the point $(2,0,1)$ and parallel to the vector ${\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)$ and $(0,2,0)$
  3. The plane passing through the point $(2,0,1)$ and perpendicular to the vector $-{\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=3$ and $x-2y+3z=1$.
  6. Show the planes and the line of intersection in your plot.

︡39ac6322-5f8d-41d3-9964-0c56743c5a22︡{"hide":"input"}︡{"html":"\nExample 1: Find and plot each of the following as instructed:

\n
    \n\n
  1. The line passing through the point $(2,0,1)$ and\nparallel to the vector ${\\bf i} + {\\bf j} - {\\bf k}$.
    \nShow the line and the parallel vector in your plot.
    \n
  2. \n\n
  3. The line passing through the points $(2,0,1)$ and\n$(0,2,0)$
  4. \n\n
  5. The plane passing through the point $(2,0,1)$ and\nperpendicular to the vector $-{\\bf i} - {\\bf j} - {\\bf k}$.
  6. \nShow the vector and the plane in your plot.\n\n
  7. The line of intersection of the planes $3x+2y+z=3$ and\n$x-2y+3z=1$.
  8. \nShow the planes and the line of intersection in your plot.\n\n
\n
\n

"}︡{"done":true}︡ ︠b8b9a0ac-9313-499a-babc-b631ba277462︠ # 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) ︡51fe993c-77fc-4786-ae73-0cd66db194de︡{"stdout":"(t + 2, t, -t + 1)\n"}︡{"file":{"filename":"598125e8-f501-4656-8161-9da5aeaaf87f.sage3d","uuid":"598125e8-f501-4656-8161-9da5aeaaf87f"}}︡{"done":true}︡ ︠a68bd995-b722-4e2f-9554-54fc82fc7d3a︠ # 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) ︡04aba6e1-c8c1-4c93-abaa-60b30ffcfcca︡{"stdout":"(-2*t + 2, 2*t, -t + 1)\n"}︡{"file":{"filename":"a38c865d-9137-40f8-a904-7aa800188640.sage3d","uuid":"a38c865d-9137-40f8-a904-7aa800188640"}}︡{"done":true}︡ ︠657e4248-5f51-415a-9495-d2e0a1ebf5ab︠ # 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 = , 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) ︡dbbadecd-471f-4641-9ee8-bebe1a056ec1︡{"stdout":"The plane is: -x - y - z + 3 = 0\n"}︡{"stdout":" \n"}︡{"file":{"filename":"c298ea93-dfba-47cb-9739-5d966077f592.sage3d","uuid":"c298ea93-dfba-47cb-9739-5d966077f592"}}︡{"done":true}︡ ︠22cf51c1-9814-48cd-a09c-7af34ecfcea1︠ # 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' ) ︡b816b435-9261-4da0-b586-d4246df756b5︡{"stdout":"x = -r22 + 1 , y = r22 , z = r22\n"}︡{"done":true}︡ ︠e4c03c44-a318-473e-a25e-4f33b071e2ec︠ rp = parametric_plot( (1-t, t, t), (t,-5,5), color='yellow', thickness=5) show(pp+qp+rp) ︡26b1ce53-744d-424b-a3f4-828a244f4baa︡{"file":{"filename":"98365c30-bae2-452c-a9ab-484b47971e0c.sage3d","uuid":"98365c30-bae2-452c-a9ab-484b47971e0c"}}︡{"done":true}︡ ︠e8560fed-996c-44ae-b20c-fdf479c75c16is︠ %hide %html 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. ︡7a29e32c-a0f2-420e-a03f-69845aa6a48a︡{"hide":"input"}︡{"html":"Exercise 1:\n\nDo these problems from Sec.9.5 of our textbook:\n

\n5, 23, 45.\n

\nIn all cases, use Sage to do your computations and to \ngraph your results.\n"}︡{"done":true}︡ ︠1d654cb1-b652-4250-a5ed-dccb9042edd0is︠ %hide %html

Plotting other simple surfaces in 3D

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

︡351a4375-2a3f-44ec-a613-cef2ce45c4d3︡{"hide":"input"}︡{"html":"

Plotting other simple surfaces in 3D

\n\n

\nWe conclude with a brief glimpse of plotting more general \nsurfaces in 3D.\n

"}︡{"done":true}︡ ︠29b8a4c1-a5c4-4e7e-99a1-1104390ac29di︠ %hide %html Example 2: Plot each of the following as instructed:

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

︡eb663cb5-5b74-44ea-8305-7b9482d6db9d︡{"hide":"input"}︡{"html":"\nExample 2: Plot each of the following as instructed:

\n
    \n\n
  1. The equation $y=-x^2+1$ in $\\mathbb{R^2}$, and then in \n$\\mathbb{R^3}$ (on separate plots, please!).\n
  2. \n\n
  3. Graph the surface $x^2+3z^2=4$ and describe what it \nlooks like
  4. \n\n
  5. Graph the surface $xyz=3$.
  6. \n\n
  7. show graphically that the curve of intersection of \nthe surfaces $x^2+2y^2-z^2+3x = 1$ and $2x^2+4y^2-2z^2-5y == 0$\nlies in a plane.
  8. \n\n
\n
\n

"}︡{"done":true}︡ ︠868cdc96-c2ad-4365-bf07-0948097c6f64︠ # 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' ) ︡fed0b610-1517-4b96-bbde-586da4a59eea︡{"file":{"filename":"/home/user/.sage/temp/project-197cad8e-828e-432b-bf71-ab88041c5a29/139/tmp_var6bE.svg","show":true,"text":null,"uuid":"e19fb26f-701e-4bd8-a093-0e6f2ac533a5"},"once":false}︡{"file":{"filename":"53192fe7-fb7a-467c-bcd1-83f204ee02fa.sage3d","uuid":"53192fe7-fb7a-467c-bcd1-83f204ee02fa"}}︡{"done":true}︡ ︠d927b73a-9259-4fb7-bf0b-44ddb72e7081︠ # 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' ) ︡8a686133-997d-4821-810c-9af888687c08︡{"file":{"filename":"d1b5e28e-11d8-440f-a027-f690fab4cbe8.sage3d","uuid":"d1b5e28e-11d8-440f-a027-f690fab4cbe8"}}︡{"done":true}︡ ︠b85f72b6-e875-4285-a38b-2a23c087483ci︠ %hide %html Example 2b: continued

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

︡b7ed13b2-0960-47f9-859c-fb4789e19ced︡{"hide":"input"}︡{"html":"Example 2b: continued

\n\nBy rotating the 3D plot above, it looks like an elliptic \ncylinder, with center along the $y$-axis.\n\n

"}︡{"done":true}︡ ︠29862d0f-b6d7-4abe-97cc-0962ca23e3e9︠ # Example 2c: Graph the surface xyz=3: implicit_plot3d(x*y*z == 3, (x,-5,5), (y,-5,5), (z,-5,5), color='purple' ) ︡e946fba6-69da-4fbe-bab3-bbc14213e0fb︡{"file":{"filename":"0bc0e6f8-592e-4961-9b38-41678ddabf48.sage3d","uuid":"0bc0e6f8-592e-4961-9b38-41678ddabf48"}}︡{"done":true}︡ ︠2c42259f-9ad7-4f48-b2a9-348f712b430f︠ # 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) ︡3ebb4478-5912-4727-93ed-55496c1ed374︡{"file":{"filename":"be96a1e8-0a6c-4392-9c44-07cd7c255e56.sage3d","uuid":"be96a1e8-0a6c-4392-9c44-07cd7c255e56"}}︡{"done":true}︡ ︠2cc6f2a8-85de-4d17-b74b-4d09a0ec15c6si︠ %hide %html 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


$(x^2+(9/4)y^2+z^2-1)^3 -x^2z^3 - (9/80)y^2 z^3 = 0$,     on $x, y, z \in [-1.5,1.5]$, with red color. ︡830bbcb3-c053-4c3b-9e8f-81624c5d8d8e︡{"hide":"input"}︡{"html":"Exercise 2:\n\nDo these problems from Sec.9.6 of our textbook:\n

\n15(f), 23, 31.\n

\nHere is an extra exercise: Graph the following surface and \ndetermine what it looks like\n\n


\n$(x^2+(9/4)y^2+z^2-1)^3 -x^2z^3 - (9/80)y^2 z^3 = 0$, \n     on $x, y, z \\in [-1.5,1.5]$, with red color."}︡{"done":true}︡