# Plotting surfaces over non-rectangular domain I'm wondering if we can plot a surface over non-rectangular domain. E.g.

plot3d(lambda x, y: 2 + sin(x) + cos(y) if y < 2*pi - x else False, (x,x0,x1), (y,y0,y1))


or something. I've tried playing with the domain like

implicit_plot3d( (s,t,2+sin(s)+cos(t)), (s,0,2*pi), (t,0 2*pi - s) )


but again no dice. I'm sure I could just draw a whole bunch of polygons but I wonder if there's a better way.

edit retag close merge delete

Sort by » oldest newest most voted Like this

sage: var('x,y,z')
(x, y, z)
sage: P = plot3d(2 + sin(x) + cos(y), (x,-1,1), (y,-1,1))
sage: def condition(x,y,z):
....:     return bool(x*x<y)

more

I'm accepting this one because it would allow me to restrict a whole plot ex post facto which seems really versatile.

You could find a parametrization of the domain and then use parametric plot. For example, for the triangular region:

f(x,y) = 2 + sin(x) + cos(y)
parametric_plot3d((x, y*(2*pi-x), f(x, y*(2*pi-x))), (x, 0, 2*pi), (y, 0, 1), mesh=True)


Alternatively, though not as pretty, you could use an implicit plot like this:

var('x,y,z')
implicit_plot3d(z - f(x,y), (x, 0, 2*pi), (y, 0, 2*pi), (z, 0, 4), region=lambda x, y, z: bool(y < 2*pi - x))

more

I can't believe I didn't think of the first one! Thanks - these are both really good answers which I'm certain I'll use.