# plotting regions in 3D

I have recently learned to plot regions in the xy-plane as follows:

region_plot([y - 2*x<= 0, 0<x, x<2, 0<y, y<3], (x, -3, 3), (y, -3, 3))


My question is: How do I plot the same region, but living in 3-space? How do I add an extra condition (namely, z=0) so that the region appears in 3-space? The reason I ask is that I want to plot a two-varialbe function and its region of integration in the same plot.

edit retag close merge delete

Sort by » oldest newest most voted

You can use implicit_plot3d as follows:

sage: region = implicit_plot3d(z, (x, -3, 3), (y, -3, 3), (z, -3, 3), plot_points=100, region=lambda x,y,z: y - 2*x<= 0 and 0<x and x<2 and 0<y and y<3)
sage: region.show()

more

Thank you for your help. What does that lambda command do? Also, suppose I want to extend that region upward; that is, let z >=0 and get a solid. Is there an easy tweak to your code to do that?

( 2013-09-22 05:38:50 -0500 )edit

This comment box destroys some symbols, see my answer below.

( 2013-09-22 08:22:59 -0500 )edit

The line

lambda x,y,z: y - 2*x<= 0 and 0<x and x<2 and 0<y and y<3


just defines a function that takes x,y,z as arguments, and that returns the boolean (y - 2*x<= 0 and 0<x and x<2 and 0<y and y<3).

sage: implicit_plot3d(0, (x, -3, 3), (y, -3, 3), (z, -3, 3), plot_points=100, region=lambda x,y,z: y - 2*x<= 0 and 0<x and x<2 and 0<y and y<3).show()


but the function 0 does not define a surface but a volume, and plot3d does not show anything.

A possible workaround could be to plot many parallel surfaces:

sage: implicit_plot3d(z, (x, -3, 3), (y, -3, 3), (z, -3, 3), plot_points=100, contour=[i/100 for i in range(100)], region=lambda x,y,z: y - 2*x<= 0 and 0<x and x<2 and 0<y and y<3).show()

more