Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

All published worksheets from http://sagenb.org

Views: 168769
Image: ubuntu2004

As a continuation of the recent cloning of ploting methods found in mathematica. I've started a clone of RevolutionPlot3D.
http://reference.wolfram.com/mathematica/ref/RevolutionPlot3D.html

My version, however, can specify the axis of rotation of the curve, given as a line paralel to the z axis, located in the point of coordinates (x,y)(x,y). And also, the posibility to display the revolved curve.

The corresponding ticket is http://trac.sagemath.org/sage_trac/ticket/7889

def revolution_plot(cur,trange,phirange=None,axis=(0,0),showcurve=False,**kwds): def findvar(expr): try: vart=cur.args()[0] except: vart=var('t') return vart if phirange==None:#this if-else provides a phirange phi=var('phi') phirange=(phi,0,2*pi) else: phi=phirange[0] phirange=(phi,phirange[1],phirange[2]) if str(type(cur)) == "<type 'tuple'>":#this if-else provides a vector v to be ploted vart=findvar(cur[0]) R=sqrt((cur[0]-axis[0])^2+axis[1]^2) v=(R*cos(phi)+axis[0],R*sin(phi)+axis[1],cur[1]) curveplot=parametric_plot3d((cur[0],0,cur[1]),trange,thickness=2,rgbcolor=(1,0,0)) elif str(type(cur))== "<type 'list'>": vart=findvar(cur[0]) R=sqrt((cur[0]-axis[0])^2+axis[1]^2) v=(R*cos(phi)+axis[0],R*sin(phi)+axis[1],cur[1]) curveplot=parametric_plot3d((cur[0],0,cur[1]),trange,thickness=2,rgbcolor=(1,0,0)) else: vart=findvar(cur) R=sqrt((vart-axis[0])^2+(axis[1])^2) v=(R*cos(phi)+axis[0],R*sin(phi)+axis[1],cur) curveplot=parametric_plot3d((vart,0,cur),trange,thickness=2,rgbcolor=(1,0,0)) if showcurve: return parametric_plot3d(v,trange,phirange,**kwds)+curveplot return parametric_plot3d(v,trange,phirange,**kwds)

Let's clone the examples in the link above

var('t,fi') torus=(2+cos(2*pi*t),sin(2*pi*t)) pot=t^4-t^2 k=2 def g(t): if t>0.5: return t else: return t^2
plot=revolution_plot(pot,(t,0,1),showcurve=True,opacity=0.5).show(aspect_ratio=(1,1,3))
revolution_plot(torus,(t,0,1),showcurve=True,opacity=0.5).show(aspect_ratio=(1,1,1))

Now let's revolve those curves around different axes and see what happens.

plot=revolution_plot(pot,(t,0,1),axis=(1,0),showcurve=True,opacity=0.5).show(aspect_ratio=(1,1,3))
plot=revolution_plot(pot,(t,0,1),axis=(0.5,0.5),showcurve=True,opacity=0.5).show(aspect_ratio=(1,1,3))
revolution_plot(torus,(t,0,1),axis=(1.5,1),showcurve=True,opacity=0.5).show(aspect_ratio=(1,1,1))
revolution_plot(torus,(t,0,1),axis=(2,1),showcurve=True,opacity=0.5).show(aspect_ratio=(1,1,1))

Non-symbolical functions have been troublesome. I would appreciate help to support themwhich I can't explain...
Mathematica also supports revolutions of 3d curves, that will require further thinking.

Now another example shamelessly stolen from Mathematica:

revolution_plot((sin(t)+sin(9*t)/5,cos(t)+cos(9*t)/5),(t,0,pi),(fi,0,pi),plotpoints=[150,150]).show(aspect_ratio=(1,1,1),frame=False)