Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagesmc
Path: blob/master/src/sage/geometry/riemannian_manifolds/surface3d_generators.py
8817 views
1
r"""
2
Common parametrized surfaces in 3D.
3
4
AUTHORS::
5
6
- Joris Vankerschaver (2012-06-16)
7
8
"""
9
10
#*****************************************************************************
11
# Copyright (C) 2010 Joris Vankerschaver <[email protected]>
12
#
13
# Distributed under the terms of the GNU General Public License (GPL)
14
# http://www.gnu.org/licenses/
15
#*****************************************************************************
16
17
18
from sage.symbolic.constants import pi
19
from sage.functions.log import log
20
from sage.functions.trig import sin, cos, tan
21
from sage.functions.hyperbolic import cosh, sinh, tanh
22
from sage.symbolic.ring import SR, var
23
from sage.geometry.riemannian_manifolds.parametrized_surface3d import \
24
ParametrizedSurface3D
25
26
27
class SurfaceGenerators():
28
"""
29
A class consisting of generators for several common parametrized surfaces
30
in 3D.
31
32
"""
33
@staticmethod
34
def Catenoid(c=1, name="Catenoid"):
35
r"""
36
Returns a catenoid surface, with parametric representation
37
38
.. MATH::
39
40
\begin{aligned}
41
x(u, v) & = c \cosh(v/c) \cos(u); \\
42
y(u, v) & = c \cosh(v/c) \sin(u); \\
43
z(u, v) & = v.
44
\end{aligned}
45
46
INPUT:
47
48
- ``c`` -- surface parameter.
49
50
- ``name`` -- string. Name of the surface.
51
52
53
EXAMPLES::
54
55
sage: cat = surfaces.Catenoid(); cat
56
Parametrized surface ('Catenoid') with equation (cos(u)*cosh(v), cosh(v)*sin(u), v)
57
sage: cat.plot()
58
59
"""
60
u, v = var('u, v')
61
catenoid_eq = [c*cosh(v/c)*cos(u), c*cosh(v/c)*sin(u), v]
62
coords = ((u, 0, 2*pi), (v, -1, 1))
63
64
return ParametrizedSurface3D(catenoid_eq, coords, name)
65
66
@staticmethod
67
def Crosscap(r=1, name="Crosscap"):
68
r"""
69
Returns a crosscap surface, with parametrization
70
71
.. MATH::
72
73
\begin{aligned}
74
x(u, v) & = r(1 + \cos(v)) \cos(u); \\
75
y(u, v) & = r(1 + \cos(v)) \sin(u); \\
76
z(u, v) & = - r\tanh(u - \pi) \sin(v).
77
\end{aligned}
78
79
INPUT:
80
81
- ``r`` -- surface parameter.
82
83
- ``name`` -- string. Name of the surface.
84
85
EXAMPLES::
86
87
sage: crosscap = surfaces.Crosscap(); crosscap
88
Parametrized surface ('Crosscap') with equation ((cos(v) + 1)*cos(u), (cos(v) + 1)*sin(u), -sin(v)*tanh(-pi + u))
89
sage: crosscap.plot()
90
91
"""
92
93
u, v = var('u, v')
94
crosscap_eq = [r*(1+cos(v))*cos(u), r*(1+cos(v))*sin(u),
95
-tanh(u-pi)*r*sin(v)]
96
coords = ((u, 0, 2*pi), (v, 0, 2*pi))
97
98
return ParametrizedSurface3D(crosscap_eq, coords, name)
99
100
@staticmethod
101
def Dini(a=1, b=1, name="Dini's surface"):
102
r"""
103
Returns Dini's surface, with parametrization
104
105
.. MATH::
106
107
\begin{aligned}
108
x(u, v) & = a \cos(u)\sin(v); \\
109
y(u, v) & = a \sin(u)\sin(v); \\
110
z(u, v) & = u + \log(\tan(v/2)) + \cos(v).
111
\end{aligned}
112
113
INPUT:
114
115
- ``a, b`` -- surface parameters.
116
117
- ``name`` -- string. Name of the surface.
118
119
EXAMPLES::
120
121
sage: dini = surfaces.Dini(a=3, b=4); dini
122
Parametrized surface ('Dini's surface') with equation (3*cos(u)*sin(v), 3*sin(u)*sin(v), 4*u + 3*cos(v) + 3*log(tan(1/2*v)))
123
sage: dini.plot() # not tested -- known bug (see #10132)
124
125
"""
126
127
u, v = var('u, v')
128
dini_eq = [a*cos(u)*sin(v), a*sin(u)*sin(v),
129
a*(cos(v) + log(tan(v/2))) + b*u]
130
coords = ((u, 0, 2*pi), (v, 0, 2*pi))
131
132
133
return ParametrizedSurface3D(dini_eq, coords, name)
134
135
@staticmethod
136
def Ellipsoid(center=(0,0,0), axes=(1,1,1), name="Ellipsoid"):
137
r"""
138
Returns an ellipsoid centered at ``center`` whose semi-principal axes
139
have lengths given by the components of ``axes``. The
140
parametrization of the ellipsoid is given by
141
142
.. MATH::
143
144
\begin{aligned}
145
x(u, v) & = x_0 + a \cos(u) \cos(v); \\
146
y(u, v) & = y_0 + b \sin(u) \cos(v); \\
147
z(u, v) & = z_0 + c \sin(v).
148
\end{aligned}
149
150
INPUT:
151
152
- ``center`` -- 3-tuple. Coordinates of the center of the ellipsoid.
153
154
- ``axes`` -- 3-tuple. Lengths of the semi-principal axes.
155
156
- ``name`` -- string. Name of the ellipsoid.
157
158
EXAMPLES::
159
160
sage: ell = surfaces.Ellipsoid(axes=(1, 2, 3)); ell
161
Parametrized surface ('Ellipsoid') with equation (cos(u)*cos(v), 2*cos(v)*sin(u), 3*sin(v))
162
sage: ell.plot()
163
164
"""
165
166
u, v = var ('u, v')
167
x, y, z = center
168
a, b, c = axes
169
ellipsoid_parametric_eq = [x + a*cos(u)*cos(v),
170
y + b*sin(u)*cos(v),
171
z + c*sin(v)]
172
coords = ((u, 0, 2*pi), (v, -pi/2, pi/2))
173
174
return ParametrizedSurface3D(ellipsoid_parametric_eq, coords, name)
175
176
@staticmethod
177
def Enneper(name="Enneper's surface"):
178
r"""
179
Returns Enneper's surface, with parametrization
180
181
.. MATH::
182
183
\begin{aligned}
184
x(u, v) & = u(1 - u^2/3 + v^2)/3; \\
185
y(u, v) & = -v(1 - v^2/3 + u^2)/3; \\
186
z(u, v) & = (u^2 - v^2)/3.
187
\end{aligned}
188
189
INPUT:
190
191
- ``name`` -- string. Name of the surface.
192
193
EXAMPLES::
194
195
sage: enn = surfaces.Enneper(); enn
196
Parametrized surface ('Enneper's surface') with equation (-1/9*(u^2 - 3*v^2 - 3)*u, -1/9*(3*u^2 - v^2 + 3)*v, 1/3*u^2 - 1/3*v^2)
197
sage: enn.plot()
198
199
"""
200
201
u, v = var('u, v')
202
enneper_eq = [u*(1-u**2/3+v**2)/3, -v*(1-v**2/3+u**2)/3, (u**2-v**2)/3]
203
coords = ((u, -3, 3), (v, -3, 3))
204
205
return ParametrizedSurface3D(enneper_eq, coords, name)
206
207
@staticmethod
208
def Helicoid(h=1, name="Helicoid"):
209
r"""
210
Returns a helicoid surface, with parametrization
211
212
.. MATH::
213
214
\begin{aligned}
215
x(\rho, \theta) & = \rho \cos(\theta); \\
216
y(\rho, \theta) & = \rho \sin(\theta); \\
217
z(\rho, \theta) & = h\theta/(2\pi).
218
\end{aligned}
219
220
INPUT:
221
222
- ``h`` -- distance along the z-axis between two
223
successive turns of the helicoid.
224
225
- ``name`` -- string. Name of the surface.
226
227
EXAMPLES::
228
229
sage: helicoid = surfaces.Helicoid(h=2); helicoid
230
Parametrized surface ('Helicoid') with equation (rho*cos(theta), rho*sin(theta), theta/pi)
231
sage: helicoid.plot()
232
233
"""
234
235
rho, theta = var('rho, theta')
236
helicoid_eq = [rho*cos(theta), rho*sin(theta), h*theta/(2*pi)]
237
coords = ((rho, -2, 2), (theta, 0, 2*pi))
238
239
return ParametrizedSurface3D(helicoid_eq, [rho, theta], name)
240
241
@staticmethod
242
def Klein(r=1, name="Klein bottle"):
243
r"""
244
Returns the Klein bottle, in the figure-8 parametrization given by
245
246
.. MATH::
247
248
\begin{aligned}
249
x(u, v) & = (r + \cos(u/2)\cos(v) - \sin(u/2)\sin(2v)) \cos(u); \\
250
y(u, v) & = (r + \cos(u/2)\cos(v) - \sin(u/2)\sin(2v)) \sin(u); \\
251
z(u, v) & = \sin(u/2)\cos(v) + \cos(u/2)\sin(2v).
252
\end{aligned}
253
254
INPUT:
255
256
- ``r`` -- radius of the "figure-8" circle.
257
258
- ``name`` -- string. Name of the surface.
259
260
EXAMPLES::
261
262
sage: klein = surfaces.Klein(); klein
263
Parametrized surface ('Klein bottle') with equation (-(sin(1/2*u)*sin(2*v) - cos(1/2*u)*sin(v) - 1)*cos(u), -(sin(1/2*u)*sin(2*v) - cos(1/2*u)*sin(v) - 1)*sin(u), cos(1/2*u)*sin(2*v) + sin(1/2*u)*sin(v))
264
sage: klein.plot()
265
266
"""
267
268
u, v = var('u, v')
269
x = (r + cos(u/2)*sin(v) - sin(u/2)*sin(2*v))*cos(u)
270
y = (r + cos(u/2)*sin(v) - sin(u/2)*sin(2*v))*sin(u)
271
z = sin(u/2)*sin(v) + cos(u/2)*sin(2*v)
272
klein_eq = [x, y, z]
273
coords = ((u, 0, 2*pi), (v, 0, 2*pi))
274
275
return ParametrizedSurface3D(klein_eq, coords, name)
276
277
@staticmethod
278
def MonkeySaddle(name="Monkey saddle"):
279
r"""
280
Returns a monkey saddle surface, with equation
281
282
.. MATH::
283
284
z = x^3 - 3xy^2.
285
286
INPUT:
287
288
- ``name`` -- string. Name of the surface.
289
290
EXAMPLES::
291
292
sage: saddle = surfaces.MonkeySaddle(); saddle
293
Parametrized surface ('Monkey saddle') with equation (u, v, u^3 - 3*u*v^2)
294
sage: saddle.plot()
295
296
"""
297
298
u, v = var('u, v')
299
monkey_eq = [u, v, u**3 - 3*u*v**2]
300
coords = ((u, -2, 2), (v, -2, 2))
301
302
return ParametrizedSurface3D(monkey_eq, coords, name)
303
304
@staticmethod
305
def Paraboloid(a=1, b=1, c=1, elliptic=True, name=None):
306
r"""
307
Returns a paraboloid with equation
308
309
.. MATH::
310
311
\frac{z}{c} = \pm \frac{x^2}{a^2} + \frac{y^2}{b^2}
312
313
When the plus sign is selected, the paraboloid is elliptic. Otherwise
314
the surface is a hyperbolic paraboloid.
315
316
INPUT:
317
318
- ``a``, ``b``, ``c`` -- Surface parameters.
319
320
- ``elliptic`` (default: True) -- whether to create an elliptic or
321
hyperbolic paraboloid.
322
323
- ``name`` -- string. Name of the surface.
324
325
EXAMPLES::
326
327
sage: epar = surfaces.Paraboloid(1, 3, 2); epar
328
Parametrized surface ('Elliptic paraboloid') with equation (u, v, 2*u^2 + 2/9*v^2)
329
sage: epar.plot()
330
331
sage: hpar = surfaces.Paraboloid(2, 3, 1, elliptic=False); hpar
332
Parametrized surface ('Hyperbolic paraboloid') with equation (u, v, -1/4*u^2 + 1/9*v^2)
333
sage: hpar.plot()
334
335
"""
336
337
u, v = var('u, v')
338
x = u; y = v
339
if elliptic:
340
z = c*(v**2/b**2 + u**2/a**2)
341
else:
342
z = c*(v**2/b**2 - u**2/a**2)
343
paraboloid_eq = [x, y, z]
344
coords = ((u, -3, 3), (v, -3, 3))
345
346
if name is None:
347
if elliptic:
348
name = "Elliptic paraboloid"
349
else:
350
name = "Hyperbolic paraboloid"
351
352
return ParametrizedSurface3D(paraboloid_eq, coords, name)
353
354
@staticmethod
355
def Sphere(center=(0,0,0), R=1, name="Sphere"):
356
r"""
357
Returns a sphere of radius ``R`` centered at ``center``.
358
359
INPUT:
360
361
- ``center`` -- 3-tuple, center of the sphere.
362
363
- ``R`` -- Radius of the sphere.
364
365
- ``name`` -- string. Name of the surface.
366
367
EXAMPLES::
368
369
sage: sphere = surfaces.Sphere(center=(0, 1, -1), R=2); sphere
370
Parametrized surface ('Sphere') with equation (2*cos(u)*cos(v), 2*cos(v)*sin(u) + 1, 2*sin(v) - 1)
371
sage: sphere.plot()
372
373
Note that the radius of the sphere can be negative. The surface thus
374
obtained is equal to the sphere (or part thereof) with positive radius,
375
whose coordinate functions have been multiplied by -1. Compare for
376
instant the first octant of the unit sphere with positive radius::
377
378
sage: octant1 = surfaces.Sphere(R=1); octant1
379
Parametrized surface ('Sphere') with equation (cos(u)*cos(v), cos(v)*sin(u), sin(v))
380
sage: octant1.plot((0, pi/2), (0, pi/2))
381
382
with the first octant of the unit sphere with negative radius::
383
384
sage: octant2 = surfaces.Sphere(R=-1); octant2
385
Parametrized surface ('Sphere') with equation (-cos(u)*cos(v), -cos(v)*sin(u), -sin(v))
386
sage: octant2.plot((0, pi/2), (0, pi/2))
387
388
"""
389
390
return SurfaceGenerators.Ellipsoid(center, (R, R, R), name)
391
392
@staticmethod
393
def Torus(r=2, R=3, name="Torus"):
394
r"""
395
Returns a torus obtained by revolving a circle of radius ``r`` around
396
a coplanar axis ``R`` units away from the center of the circle. The
397
parametrization used is
398
399
.. MATH::
400
401
\begin{aligned}
402
x(u, v) & = (R + r \cos(v)) \cos(u); \\
403
y(u, v) & = (R + r \cos(v)) \sin(u); \\
404
z(u, v) & = r \sin(v).
405
\end{aligned}
406
407
INPUT:
408
409
- ``r``, ``R`` -- Minor and major radius of the torus.
410
411
- ``name`` -- string. Name of the surface.
412
413
EXAMPLES::
414
415
sage: torus = surfaces.Torus(); torus
416
Parametrized surface ('Torus') with equation ((2*cos(v) + 3)*cos(u), (2*cos(v) + 3)*sin(u), 2*sin(v))
417
sage: torus.plot()
418
419
"""
420
421
u, v = var('u, v')
422
torus_eq = [(R+r*cos(v))*cos(u), (R+r*cos(v))*sin(u), r*sin(v)]
423
coords = ((u, 0, 2*pi), (v, 0, 2*pi))
424
425
return ParametrizedSurface3D(torus_eq, coords, name)
426
427
@staticmethod
428
def WhitneyUmbrella(name="Whitney's umbrella"):
429
r"""
430
Returns Whitney's umbrella, with parametric representation
431
432
.. MATH::
433
434
x(u, v) = uv, \quad y(u, v) = u, \quad z(u, v) = v^2.
435
436
INPUT:
437
438
- ``name`` -- string. Name of the surface.
439
440
EXAMPLES::
441
442
sage: whitney = surfaces.WhitneyUmbrella(); whitney
443
Parametrized surface ('Whitney's umbrella') with equation (u*v, u, v^2)
444
sage: whitney.plot()
445
446
"""
447
448
u, v = var('u, v')
449
whitney_eq = [u*v, u, v**2]
450
coords = ((u, -1, 1), (v, -1, 1))
451
452
return ParametrizedSurface3D(whitney_eq, coords, name)
453
454
455
# Easy access to the surface generators
456
surfaces = SurfaceGenerators()
457
458
459