Ask Your Question

Plotting surfaces over non-rectangular domain

asked 2020-05-21 23:56:26 +0200

Shai gravatar image

updated 2020-05-25 11:23:00 +0200

FrédéricC gravatar image

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 flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted

answered 2020-05-22 09:25:31 +0200

FrédéricC gravatar image

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)
sage: P.add_condition(condition)
edit flag offensive delete link more


Nice. I did not know about that.

mwageringel gravatar imagemwageringel ( 2020-05-22 09:48:12 +0200 )edit

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

Shai gravatar imageShai ( 2020-05-23 14:33:02 +0200 )edit

answered 2020-05-22 09:45:59 +0200

mwageringel gravatar image

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:

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))
edit flag offensive delete link 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.

Shai gravatar imageShai ( 2020-05-23 14:38:45 +0200 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2020-05-21 23:56:26 +0200

Seen: 542 times

Last updated: May 22 '20