Path: blob/master/src/sage/geometry/riemannian_manifolds/surface3d_generators.py
8817 views
r"""1Common parametrized surfaces in 3D.23AUTHORS::45- Joris Vankerschaver (2012-06-16)67"""89#*****************************************************************************10# Copyright (C) 2010 Joris Vankerschaver <[email protected]>11#12# Distributed under the terms of the GNU General Public License (GPL)13# http://www.gnu.org/licenses/14#*****************************************************************************151617from sage.symbolic.constants import pi18from sage.functions.log import log19from sage.functions.trig import sin, cos, tan20from sage.functions.hyperbolic import cosh, sinh, tanh21from sage.symbolic.ring import SR, var22from sage.geometry.riemannian_manifolds.parametrized_surface3d import \23ParametrizedSurface3D242526class SurfaceGenerators():27"""28A class consisting of generators for several common parametrized surfaces29in 3D.3031"""32@staticmethod33def Catenoid(c=1, name="Catenoid"):34r"""35Returns a catenoid surface, with parametric representation3637.. MATH::3839\begin{aligned}40x(u, v) & = c \cosh(v/c) \cos(u); \\41y(u, v) & = c \cosh(v/c) \sin(u); \\42z(u, v) & = v.43\end{aligned}4445INPUT:4647- ``c`` -- surface parameter.4849- ``name`` -- string. Name of the surface.505152EXAMPLES::5354sage: cat = surfaces.Catenoid(); cat55Parametrized surface ('Catenoid') with equation (cos(u)*cosh(v), cosh(v)*sin(u), v)56sage: cat.plot()5758"""59u, v = var('u, v')60catenoid_eq = [c*cosh(v/c)*cos(u), c*cosh(v/c)*sin(u), v]61coords = ((u, 0, 2*pi), (v, -1, 1))6263return ParametrizedSurface3D(catenoid_eq, coords, name)6465@staticmethod66def Crosscap(r=1, name="Crosscap"):67r"""68Returns a crosscap surface, with parametrization6970.. MATH::7172\begin{aligned}73x(u, v) & = r(1 + \cos(v)) \cos(u); \\74y(u, v) & = r(1 + \cos(v)) \sin(u); \\75z(u, v) & = - r\tanh(u - \pi) \sin(v).76\end{aligned}7778INPUT:7980- ``r`` -- surface parameter.8182- ``name`` -- string. Name of the surface.8384EXAMPLES::8586sage: crosscap = surfaces.Crosscap(); crosscap87Parametrized surface ('Crosscap') with equation ((cos(v) + 1)*cos(u), (cos(v) + 1)*sin(u), -sin(v)*tanh(-pi + u))88sage: crosscap.plot()8990"""9192u, v = var('u, v')93crosscap_eq = [r*(1+cos(v))*cos(u), r*(1+cos(v))*sin(u),94-tanh(u-pi)*r*sin(v)]95coords = ((u, 0, 2*pi), (v, 0, 2*pi))9697return ParametrizedSurface3D(crosscap_eq, coords, name)9899@staticmethod100def Dini(a=1, b=1, name="Dini's surface"):101r"""102Returns Dini's surface, with parametrization103104.. MATH::105106\begin{aligned}107x(u, v) & = a \cos(u)\sin(v); \\108y(u, v) & = a \sin(u)\sin(v); \\109z(u, v) & = u + \log(\tan(v/2)) + \cos(v).110\end{aligned}111112INPUT:113114- ``a, b`` -- surface parameters.115116- ``name`` -- string. Name of the surface.117118EXAMPLES::119120sage: dini = surfaces.Dini(a=3, b=4); dini121Parametrized 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)))122sage: dini.plot() # not tested -- known bug (see #10132)123124"""125126u, v = var('u, v')127dini_eq = [a*cos(u)*sin(v), a*sin(u)*sin(v),128a*(cos(v) + log(tan(v/2))) + b*u]129coords = ((u, 0, 2*pi), (v, 0, 2*pi))130131132return ParametrizedSurface3D(dini_eq, coords, name)133134@staticmethod135def Ellipsoid(center=(0,0,0), axes=(1,1,1), name="Ellipsoid"):136r"""137Returns an ellipsoid centered at ``center`` whose semi-principal axes138have lengths given by the components of ``axes``. The139parametrization of the ellipsoid is given by140141.. MATH::142143\begin{aligned}144x(u, v) & = x_0 + a \cos(u) \cos(v); \\145y(u, v) & = y_0 + b \sin(u) \cos(v); \\146z(u, v) & = z_0 + c \sin(v).147\end{aligned}148149INPUT:150151- ``center`` -- 3-tuple. Coordinates of the center of the ellipsoid.152153- ``axes`` -- 3-tuple. Lengths of the semi-principal axes.154155- ``name`` -- string. Name of the ellipsoid.156157EXAMPLES::158159sage: ell = surfaces.Ellipsoid(axes=(1, 2, 3)); ell160Parametrized surface ('Ellipsoid') with equation (cos(u)*cos(v), 2*cos(v)*sin(u), 3*sin(v))161sage: ell.plot()162163"""164165u, v = var ('u, v')166x, y, z = center167a, b, c = axes168ellipsoid_parametric_eq = [x + a*cos(u)*cos(v),169y + b*sin(u)*cos(v),170z + c*sin(v)]171coords = ((u, 0, 2*pi), (v, -pi/2, pi/2))172173return ParametrizedSurface3D(ellipsoid_parametric_eq, coords, name)174175@staticmethod176def Enneper(name="Enneper's surface"):177r"""178Returns Enneper's surface, with parametrization179180.. MATH::181182\begin{aligned}183x(u, v) & = u(1 - u^2/3 + v^2)/3; \\184y(u, v) & = -v(1 - v^2/3 + u^2)/3; \\185z(u, v) & = (u^2 - v^2)/3.186\end{aligned}187188INPUT:189190- ``name`` -- string. Name of the surface.191192EXAMPLES::193194sage: enn = surfaces.Enneper(); enn195Parametrized 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)196sage: enn.plot()197198"""199200u, v = var('u, v')201enneper_eq = [u*(1-u**2/3+v**2)/3, -v*(1-v**2/3+u**2)/3, (u**2-v**2)/3]202coords = ((u, -3, 3), (v, -3, 3))203204return ParametrizedSurface3D(enneper_eq, coords, name)205206@staticmethod207def Helicoid(h=1, name="Helicoid"):208r"""209Returns a helicoid surface, with parametrization210211.. MATH::212213\begin{aligned}214x(\rho, \theta) & = \rho \cos(\theta); \\215y(\rho, \theta) & = \rho \sin(\theta); \\216z(\rho, \theta) & = h\theta/(2\pi).217\end{aligned}218219INPUT:220221- ``h`` -- distance along the z-axis between two222successive turns of the helicoid.223224- ``name`` -- string. Name of the surface.225226EXAMPLES::227228sage: helicoid = surfaces.Helicoid(h=2); helicoid229Parametrized surface ('Helicoid') with equation (rho*cos(theta), rho*sin(theta), theta/pi)230sage: helicoid.plot()231232"""233234rho, theta = var('rho, theta')235helicoid_eq = [rho*cos(theta), rho*sin(theta), h*theta/(2*pi)]236coords = ((rho, -2, 2), (theta, 0, 2*pi))237238return ParametrizedSurface3D(helicoid_eq, [rho, theta], name)239240@staticmethod241def Klein(r=1, name="Klein bottle"):242r"""243Returns the Klein bottle, in the figure-8 parametrization given by244245.. MATH::246247\begin{aligned}248x(u, v) & = (r + \cos(u/2)\cos(v) - \sin(u/2)\sin(2v)) \cos(u); \\249y(u, v) & = (r + \cos(u/2)\cos(v) - \sin(u/2)\sin(2v)) \sin(u); \\250z(u, v) & = \sin(u/2)\cos(v) + \cos(u/2)\sin(2v).251\end{aligned}252253INPUT:254255- ``r`` -- radius of the "figure-8" circle.256257- ``name`` -- string. Name of the surface.258259EXAMPLES::260261sage: klein = surfaces.Klein(); klein262Parametrized 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))263sage: klein.plot()264265"""266267u, v = var('u, v')268x = (r + cos(u/2)*sin(v) - sin(u/2)*sin(2*v))*cos(u)269y = (r + cos(u/2)*sin(v) - sin(u/2)*sin(2*v))*sin(u)270z = sin(u/2)*sin(v) + cos(u/2)*sin(2*v)271klein_eq = [x, y, z]272coords = ((u, 0, 2*pi), (v, 0, 2*pi))273274return ParametrizedSurface3D(klein_eq, coords, name)275276@staticmethod277def MonkeySaddle(name="Monkey saddle"):278r"""279Returns a monkey saddle surface, with equation280281.. MATH::282283z = x^3 - 3xy^2.284285INPUT:286287- ``name`` -- string. Name of the surface.288289EXAMPLES::290291sage: saddle = surfaces.MonkeySaddle(); saddle292Parametrized surface ('Monkey saddle') with equation (u, v, u^3 - 3*u*v^2)293sage: saddle.plot()294295"""296297u, v = var('u, v')298monkey_eq = [u, v, u**3 - 3*u*v**2]299coords = ((u, -2, 2), (v, -2, 2))300301return ParametrizedSurface3D(monkey_eq, coords, name)302303@staticmethod304def Paraboloid(a=1, b=1, c=1, elliptic=True, name=None):305r"""306Returns a paraboloid with equation307308.. MATH::309310\frac{z}{c} = \pm \frac{x^2}{a^2} + \frac{y^2}{b^2}311312When the plus sign is selected, the paraboloid is elliptic. Otherwise313the surface is a hyperbolic paraboloid.314315INPUT:316317- ``a``, ``b``, ``c`` -- Surface parameters.318319- ``elliptic`` (default: True) -- whether to create an elliptic or320hyperbolic paraboloid.321322- ``name`` -- string. Name of the surface.323324EXAMPLES::325326sage: epar = surfaces.Paraboloid(1, 3, 2); epar327Parametrized surface ('Elliptic paraboloid') with equation (u, v, 2*u^2 + 2/9*v^2)328sage: epar.plot()329330sage: hpar = surfaces.Paraboloid(2, 3, 1, elliptic=False); hpar331Parametrized surface ('Hyperbolic paraboloid') with equation (u, v, -1/4*u^2 + 1/9*v^2)332sage: hpar.plot()333334"""335336u, v = var('u, v')337x = u; y = v338if elliptic:339z = c*(v**2/b**2 + u**2/a**2)340else:341z = c*(v**2/b**2 - u**2/a**2)342paraboloid_eq = [x, y, z]343coords = ((u, -3, 3), (v, -3, 3))344345if name is None:346if elliptic:347name = "Elliptic paraboloid"348else:349name = "Hyperbolic paraboloid"350351return ParametrizedSurface3D(paraboloid_eq, coords, name)352353@staticmethod354def Sphere(center=(0,0,0), R=1, name="Sphere"):355r"""356Returns a sphere of radius ``R`` centered at ``center``.357358INPUT:359360- ``center`` -- 3-tuple, center of the sphere.361362- ``R`` -- Radius of the sphere.363364- ``name`` -- string. Name of the surface.365366EXAMPLES::367368sage: sphere = surfaces.Sphere(center=(0, 1, -1), R=2); sphere369Parametrized surface ('Sphere') with equation (2*cos(u)*cos(v), 2*cos(v)*sin(u) + 1, 2*sin(v) - 1)370sage: sphere.plot()371372Note that the radius of the sphere can be negative. The surface thus373obtained is equal to the sphere (or part thereof) with positive radius,374whose coordinate functions have been multiplied by -1. Compare for375instant the first octant of the unit sphere with positive radius::376377sage: octant1 = surfaces.Sphere(R=1); octant1378Parametrized surface ('Sphere') with equation (cos(u)*cos(v), cos(v)*sin(u), sin(v))379sage: octant1.plot((0, pi/2), (0, pi/2))380381with the first octant of the unit sphere with negative radius::382383sage: octant2 = surfaces.Sphere(R=-1); octant2384Parametrized surface ('Sphere') with equation (-cos(u)*cos(v), -cos(v)*sin(u), -sin(v))385sage: octant2.plot((0, pi/2), (0, pi/2))386387"""388389return SurfaceGenerators.Ellipsoid(center, (R, R, R), name)390391@staticmethod392def Torus(r=2, R=3, name="Torus"):393r"""394Returns a torus obtained by revolving a circle of radius ``r`` around395a coplanar axis ``R`` units away from the center of the circle. The396parametrization used is397398.. MATH::399400\begin{aligned}401x(u, v) & = (R + r \cos(v)) \cos(u); \\402y(u, v) & = (R + r \cos(v)) \sin(u); \\403z(u, v) & = r \sin(v).404\end{aligned}405406INPUT:407408- ``r``, ``R`` -- Minor and major radius of the torus.409410- ``name`` -- string. Name of the surface.411412EXAMPLES::413414sage: torus = surfaces.Torus(); torus415Parametrized surface ('Torus') with equation ((2*cos(v) + 3)*cos(u), (2*cos(v) + 3)*sin(u), 2*sin(v))416sage: torus.plot()417418"""419420u, v = var('u, v')421torus_eq = [(R+r*cos(v))*cos(u), (R+r*cos(v))*sin(u), r*sin(v)]422coords = ((u, 0, 2*pi), (v, 0, 2*pi))423424return ParametrizedSurface3D(torus_eq, coords, name)425426@staticmethod427def WhitneyUmbrella(name="Whitney's umbrella"):428r"""429Returns Whitney's umbrella, with parametric representation430431.. MATH::432433x(u, v) = uv, \quad y(u, v) = u, \quad z(u, v) = v^2.434435INPUT:436437- ``name`` -- string. Name of the surface.438439EXAMPLES::440441sage: whitney = surfaces.WhitneyUmbrella(); whitney442Parametrized surface ('Whitney's umbrella') with equation (u*v, u, v^2)443sage: whitney.plot()444445"""446447u, v = var('u, v')448whitney_eq = [u*v, u, v**2]449coords = ((u, -1, 1), (v, -1, 1))450451return ParametrizedSurface3D(whitney_eq, coords, name)452453454# Easy access to the surface generators455surfaces = SurfaceGenerators()456457458459