Source code for ddg.math.parametrizations._surfaces

"""Parametrizations for surfaces"""

import numpy as np


[docs]def sphere(u, v, center=None, radius=1): """ Parameterization map of a 2d sphere in 3d euclidean space with a given center and radius Parameters ---------- u: float First parameter for the parametrization. v: float Second parameter for the parametrization. center: array_like of shape (3,), (default=None) Center of the sphere. radius: float (default=1) Radius of the sphere. Returns ------- float Value of the sphere parametrization for given parameters u and v. Raises ------ ValueError If center is not 3-dimensional. Examples -------- >>> import numpy as np >>> from ddg.math.parametrizations import sphere >>> sphere(0, np.pi / 2, center=(0, 0, 0), radius=1) array([1.000000e+00, 0.000000e+00, 6.123234e-17]) """ center = np.array([0, 0, 0]) if center is None else np.array(center) if len(center) != 3: raise ValueError( "The center for the sphere must be 3 dimensional. A" f" {len(center)} dimensional ndarray was given: {center}." ) x1 = radius * np.cos(u) * np.sin(v) + center[0] x2 = radius * np.sin(u) * np.sin(v) + center[1] x3 = radius * np.cos(v) + center[2] return np.array([x1, x2, x3])
[docs]def torus(phi, theta, R, r): """ Parametrization of the torus. Parameters ---------- phi : float The value of the first parameter. theta : float The value of the second parameter. R : float Radius of the larger circle. r : float Radius of the smaller circle. Returns ------- np.ndarray of shape (3, 1) Examples -------- >>> import numpy as np >>> from ddg.math.parametrizations import torus >>> torus(np.pi / 2, np.pi / 2, 2, 1) array([1.2246468e-16, 2.0000000e+00, 1.0000000e+00]) """ return np.array( [ (R + r * np.cos(theta)) * np.cos(phi), (R + r * np.cos(theta)) * np.sin(phi), r * np.sin(theta), ] )
[docs]def mobius_strip(u, v, R): """ Parametrization of the moebius strip. Parameters ---------- u : float The value of the first parameter. v : float The value of the second parameter. R : float Radius of the midcircle of the moebius strip. Returns ------- np.ndarray of shape (3, 1) Examples -------- >>> from ddg.math.parametrizations import mobius_strip >>> mobius_strip(0, 1, 2) array([2.5, 0. , 0. ]) """ return np.array( [ (R + (v / 2) * np.cos(u / 2)) * np.cos(u), (R + (v / 2) * np.cos(u / 2)) * np.sin(u), (v / 2) * np.sin(u / 2), ] )