This notebook runs some examples of the 3D graphics section of Sage's reference manual with the three.js renderer.
version()
'SageMath version 9.0.beta4, Release Date: 2019-11-02'
x, y = var('x y')
W = plot3d(sin(pi*((x)^2+(y)^2))/2,(x,-1,1),(y,-1,1), frame=False,
color='purple', opacity=0.8)
S = sphere((0,0,0),size=0.3, color='red', aspect_ratio=[1,1,1])
show(W + S, viewer='threejs')
def f(x,y):
return math.sin(y^2+x^2)/math.sqrt(x^2+y^2+0.0001)
P = plot3d(f,(-3,3),(-3,3), adaptive=True, color=rainbow(60, 'rgbtuple'),
max_bend=.1, max_depth=15)
P.show(viewer='threejs')
S = sphere(size=.5, color='yellow')
from sage.plot.plot3d.shapes import Cone
S += Cone(.5, .5, color='red').translate(0,0,.3)
S += sphere((.45,-.1,.15), size=.1, color='white') \
+ sphere((.51,-.1,.17), size=.05, color='black')
S += sphere((.45, .1,.15),size=.1, color='white') \
+ sphere((.51, .1,.17), size=.05, color='black')
S += sphere((.5,0,-.2),size=.1, color='yellow')
def f(x,y): return math.exp(x/5)*math.cos(y)
P = plot3d(f,(-5,5),(-5,5), adaptive=True, color=['red','yellow'], max_depth=10)
cape_man = P.scale(.2) + S.translate(1,0,0)
cape_man.show(aspect_ratio=[1,1,1], viewer='threejs')
theta, z = var('theta z')
cylindrical_plot3d(e^(-z^2)*(cos(4*theta)+2)+1, (theta,0,2*pi), (z,-2,2),
plot_points=[80,80]).show(aspect_ratio=(1,1,1), viewer='threejs')
L = plot3d(lambda x,y: 0, (-5,5), (-5,5), color="lightblue", opacity=0.8)
P = plot3d(lambda x,y: 4 - x^3 - y^2, (-2,2), (-2,2), color='green')
Q = plot3d(lambda x,y: x^3 + y^2 - 4, (-2,2), (-2,2), color='orange')
show(L + P + Q, viewer='threejs')
u = var('u')
sage: parametric_plot3d((sin(u), cos(u), u/10), (u,0,20), viewer='threejs')
u, v = var('u,v')
parametric_plot3d((cos(u), sin(u)+cos(v), sin(v)), (u,0,2*pi), (v,-pi,pi),
mesh=True, viewer='threejs')
cm = colormaps.ocean
def c(x,y): return sin(x*y)**2
from sage.plot.plot3d.parametric_surface import MoebiusStrip
MoebiusStrip(5, 1, plot_points=200, color=(c,cm), viewer='threejs')
f1 = (4+(3+cos(v))*sin(u), 4+(3+cos(v))*cos(u), 4+sin(v))
f2 = (8+(3+cos(v))*cos(u), 3+sin(v), 4+(3+cos(v))*sin(u))
p1 = parametric_plot3d(f1, (u,0,2*pi), (v,0,2*pi), texture="red")
p2 = parametric_plot3d(f2, (u,0,2*pi), (v,0,2*pi), texture="blue")
(p1 + p2).show(viewer='threejs')
K = sqrt(0.84)
G = (0.4*((K*cosh(0.4*u))^2 + (0.4*sin(K*v))^2))
f_x = (2*K*cosh(0.4*u)*(-(K*cos(v)*cos(K*v)) - sin(v)*sin(K*v)))/G
f_y = (2*K*cosh(0.4*u)*(-(K*sin(v)*cos(K*v)) + cos(v)*sin(K*v)))/G
f_z = -u + (2*0.84*cosh(0.4*u)*sinh(0.4*u))/G
parametric_plot3d([f_x, f_y, f_z], (u,-13.2,13.2), (v,-37.4,37.4), plot_points=[90,90],
frame=False, color="green", viewer='threejs')
curve = (u, cos(4*u), u^2)
P = revolution_plot3d(curve, (u,0,2), show_curve=True, parallel_axis='z',
axis=(1,.2), opacity=0.5)
P.show(aspect_ratio=(1,1,1), viewer='threejs')
plot_vector_field3d((x*cos(z),-y*cos(z),sin(z)), (x,0,pi), (y,0,pi), (z,0,pi),
colors=['red','green','blue'], viewer='threejs')
implicit_plot3d((x^2 + y^2 + z^2), (x,-2,2), (y,-2,2), (z,-2,2), plot_points=60,
contour=[1,3,5], region=lambda x,y,z: x<=0.2 or y>=0.2 or z<=0.2,
color='aquamarine', viewer='threejs')