Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

All published worksheets from http://sagenb.org

Views: 168768
Image: ubuntu2004
I have finally generalized the idea of coordinate 3d plots.

Many thanks to Jason Grout for his encouragement, critique, and ideas.

Jason also suggested that it would be apropiate to include this within plot3d, to which I agreed:
Also, new commands "spherical_plot" and "cylindrical_plot" would be added.
The corresponding ticket is http://trac.sagemath.org/sage_trac/ticket/7872
def plot3d_new(f,v1ran,v2ran,transformation=None,**kwds): if transformation==None: return plot3d(f,v1ran,v2ran,**kwds) else: v1=v1ran[0] v2=v2ran[0] if transformation=='spherical': r=var('r') transformation=(r*cos(v1)*sin(v2),r*sin(v1)*sin(v2),r*cos(v2),r) elif transformation=='cylindrical': r=var('r') transformation=(r*cos(v1),r*sin(v1),v2,r) elif str(type(transformation))=="<type 'str'>": print 'Warning: the transformation given is not amongst the options, it will be ignored' return plot3d(f,v1ran,v2ran,**kwds) fvar=transformation[3] transformation=(transformation[0],transformation[1],transformation[2]) try: R=[t.subs({fvar:f}) for t in transformation] except: def subs_func(t): return lambda x,y: t.subs({fvar:f(x,y), v1:x, v2:y}) R=map(subs_func,transformation) return parametric_plot(R,v1ran,v2ran,**kwds) def spherical_plot(f,v1ran,v2ran,**kwds): return plot3d_new(f,v1ran,v2ran,'spherical',**kwds) def cylindrical_plot(f,v1ran,v2ran,**kwds): return plot3d_new(f,v1ran,v2ran,'cylindrical',**kwds)
Good! now let's plot the plot two funcions, one symbolical and one non-symbolical, each in the 3 usual coordinate systems:
var('x,y,z,r,fi,te') f=e^(-y^2)*(cos(4*x)+2)+1 def g(x,y): if y<pi/2: return 1 else: return 2
plot3d_new(f,(x,0,2*pi),(y,-2,2),plot_points=[80,80],rgbcolor=(1,.5,0),opacity=.8).show(aspect_ratio=(1,1,1))
plot3d_new(f,(x,0,2*pi),(y,-2,2),'cylindrical',plot_points=[80,80],rgbcolor=(1,.5,0),opacity=.7).show(aspect_ratio=(1,1,1))
plot3d_new(f,(x,0,2*pi),(y,-2,2),'spherical',plot_points=[80,80],rgbcolor=(1,.5,0),opacity=.7).show(aspect_ratio=(1,1,1))
plot3d_new(g,(x,0,2*pi),(y,0,pi),rgbcolor=(0.1,0.8,0.1),opacity=.6).show(aspect_ratio=(1,1,1))
plot3d_new(g,(x,0,2*pi),(y,0,pi),'cylindrical',rgbcolor=(0.1,0.8,0.1),opacity=.6).show(aspect_ratio=(1,1,1))
plot3d_new(g,(x,0,2*pi),(y,0,pi),'spherical',rgbcolor=(0.1,0.8,0.1),opacity=.6).show(aspect_ratio=(1,1,1))
These last three plots display a non vertical step, which I think is undesirable, but I can't explain it or fix it

Other transformations are surely possible, but I'll wait for others to propose them. Now an example with a different transformation
trans=[r*cos(fi),r*sin(fi),z,z] plot3d_new(cos(r),(r,0,17*pi/2),(fi,0,2*pi),transformation=trans,opacity=0.87).show(aspect_ratio=(1,1,2),frame=False)
Parabolic cylindrical coordinates now (http://en.wikipedia.org/wiki/Parabolic_cylindrical_coordinates):
var('sigma,tau,phi') a=2 xt=sigma*tau yt=(tau^2-sigma^2)/2 zt=z v=(xt,yt,zt,sigma) show(v) plot3d_new(1,(tau,-2,2),(z,-2,2),transformation=v).show(aspecta_ratio=(1,1,1))
\left(\sigma \tau, -\frac{1}{2} \, \sigma^{2} + \frac{1}{2} \, \tau^{2}, z, \sigma\right)
plot3d_new(2+cos(2*tau),(tau,-10,10),(z,-2,2),transformation=v,plot_points=[100,100]).show(aspecta_ratio=(1,1,1))