"""Parametrizations for curves, surfaces, coordinate systems, ..."""
import numpy as np
from numpy import cos, cosh, exp, sin, sinh, sqrt
from ddg.math.functions import cn, dn, sn
[docs]def confocal_conics_sqrt(u1, u2, a1, a2):
r"""2-dimensional coordinate system along confocal conics ::
x**2 / (a1 + u) + y**2 / (a2 + u) = 1 with some a1 > a2.
These are ::
hyperbolas for u = u1 with -a1 < u1 < -a2,
ellipses for u = u2 with -a2 < u2.
The parametrization is given in terms of square roots: ::
x(u1, u2) = x_sgn * sqrt(u1 + a1) * sqrt(u2 + a1) / sqrt(a1 - a2)
y(u1, u2) = y_sgn * sqrt(-(u1 + a2)) * sqrt(u2 + a2) / sqrt(a1 - a2)
With `x_sgn = y_sgn = 1` this defines a parametrization of the first quadrant.
Here the parametrization is extended to the entire plane by reflection along the
coordinate axes. This is done by computing `x_sgn` and `y_sgn` accordingly.
Parameters
----------
u1 : float in [-a1, -a2]
First parameter.
u2 : float in [-a2, inf)
Second parameter.
a1 : float with a1 > a2
Determines the first semi axis of the conics.
a2 : float with a1 > a2
Determines the second semi axis of the conics.
Returns
-------
np.ndarray of shape (2,)
Point in R^2.
"""
x1_sign = 1
x2_sign = 1
u1 = ((u1 + a1) % (4 * (a1 - a2))) - a1
if -a2 <= u1 < a1 - 2 * a2:
u1 = -u1 - 2 * a2
x2_sign *= -1
elif a1 - 2 * a2 <= u1 < 2 * a1 - 3 * a2:
u1 = u1 - 2 * (a1 - a2)
x1_sign *= -1
x2_sign *= -1
elif 2 * a1 - 3 * a2 <= u1 < 3 * a1 - 4 * a2:
u1 = -u1 + 2 * a1 - 4 * a2
x1_sign *= -1
if u2 < -a2:
u2 = -u2 - 2 * a2
x2_sign *= -1
x1 = sqrt(u1 + a1) * sqrt(u2 + a1) / sqrt(a1 - a2)
x1 *= x1_sign
x2 = sqrt(-(u1 + a2)) * sqrt(u2 + a2) / sqrt(a1 - a2)
x2 *= x2_sign
return np.array([x1, x2])
[docs]def confocal_conics_trigonometric(s1, s2, a1, a2):
r"""2-dimensional coordinate system along confocal conics ::
x**2 / (a1 + u) + y**2 / (a2 + u) = 1 with some a1 > a2.
The parametrization is given in terms of trigonometric functions: ::
x(s1, s2) = sqrt(a1 - a2) * cos(s1) * cosh(s2)
y(s1, s2) = sqrt(a1 - a2) * sin(s1) * sinh(s2)
The parametrization is 2*pi periodic in s1.
The relation to the parameters `u = u1` (hyperbolas) and `u = u2` (ellipses)
of the confocal system are given by ::
u1(s1) = (a1-a2)*cos(s1)**2 - a1
u2(s2) = (a1-a2)*cosh(s2)**2 - a1
Parameters
----------
s1 : float
First parameter.
s2 : float
Second parameter.
a1 : float with a1 > a2
Determines the first semi axis of the conics.
a2 : float with a1 > a2
Determines the second semi axis of the conics.
Returns
-------
np.ndarray of shape (2,)
Point in R^2.
"""
def f1(s1, s2, a1, a2):
return sqrt(a1 - a2) * cos(s1) * cosh(s2)
def f2(s1, s2, a1, a2):
return sqrt(a1 - a2) * sin(s1) * sinh(s2)
return np.array([f1(s1, s2, a1, a2), f2(s1, s2, a1, a2)])
[docs]def confocal_conics_concentric(s1, s2, a1, a2):
r"""2-dimensional coordinate system along confocal conics ::
x**2 / (a1 + u) + y**2 / (a2 + u) = 1 with some a1 > a2.
The parametrization is given by ::
x(s1, s2) = s1 * s2
y(s1, s2) = sqrt(1 - s1**2) * sqrt(s2**2 - 1)
The relation to the parameters `u = u1` (hyperbolas) and `u = u2` (ellipses)
of the confocal system are given by ::
u1(s1) = (a1-a2)*s1**2 - a1
u2(s2) = (a1-a2)*s2**2 - a1
The parametrization covers the upper half-plane. It is diagonally related to two
families of concentric circles with the two focii as centers.
The diagonals `s1 + s2 = xi = const` lie on concentric circles
with center `(-sqrt(a1-a2),0)` and radius `sqrt(a1-a2)*xi`.
The diagonals `s2 - s1 = eta = const` lie on concentric circles
with center `(sqrt(a1-a2),0)` and radius `sqrt(a1-a2)*eta`.
Parameters
----------
s1 : float in (-1, 1)
First parameter.
s2 : float in (1, inf)
Second parameter.
a1 : float with a1 > a2
Determines the first semi axis of the conics.
a2 : float with a1 > a2
Determines the second semi axis of the conics.
Returns
-------
np.ndarray of shape (2,)
Point in R^2.
"""
def f1(s1, s2, a1, a2):
return sqrt(a1 - a2) * s1 * s2
def f2(s1, s2, a1, a2):
return sqrt(a1 - a2) * sqrt(1 - s1**2) * sqrt(s2**2 - 1)
return np.array([f1(s1, s2, a1, a2), f2(s1, s2, a1, a2)])
[docs]def confocal_conics_ic_ellipse(s1, s2, a1, a2, k):
r"""2-dimensional coordinate system along confocal conics (outside an ellipse) ::
x**2 / (a1 + u) + y**2 / (a2 + u) = 1 with some a1 > a2.
The parametrization is given in terms of elliptic functions: ::
x(s1, s2) = sqrt(a1 - a2) * (sn(s1, k) * dn(s2, k)) / (k * cn(s2, k))
y(s1, s2) = sqrt(a1 - a2) * (sqrt(1 - k**2) * cn(s1, k)) / (k * cn(s2, k))
The relation to the parameters `u = u1` (hyperbolas) and `u = u2` (ellipses)
of the confocal system are given by ::
u1(s1) = (a1 - a2) * sn(s1)**2 - a1
u2(s2) = (a1 - a2) * (dn(s2) / (k * cn(s2)))**2 - a1
The diagonals `s1 +- s2 = const` lie on lines, which are tangent to an ellipse.
Along the `s2` direction the parametrization is bounded by this ellipse
and geos to infinity in finite time, while it is periodic along the `s1` direction.
The parametrization is closely related to incircular nets (IC-nets):
The straight diagonals of a uniform samlping of this parametrization constitutes
an IC-net.
Parameters
----------
s1 : float
First parameter (fundamental domain: [0, 2K)).
s2 : float
Second parameter (fundamental domain: (0, K)).
a1 : float with a1 > a2
Determines the first semi axis of the conics.
a2 : float with a1 > a2
Determines the second semi axis of the conics.
k : float
Modulus of the elliptic functions (0 < k**2 < 1).
Returns
-------
np.ndarray of shape (2,)
Point in R^2.
"""
def f1(s1, s2, a1, a2, k):
return sqrt(a1 - a2) * (sn(s1, k) * dn(s2, k)) / (k * cn(s2, k))
def f2(s1, s2, a1, a2, k):
return sqrt(a1 - a2) * (sqrt(1 - k**2) * cn(s1, k)) / (k * cn(s2, k))
return np.array([f1(s1, s2, a1, a2, k), f2(s1, s2, a1, a2, k)])
[docs]def confocal_conics_ic_hyperbola(s1, s2, a1, a2, k):
r"""2-dimensional coordinate system along confocal conics (outside a hyperbola) ::
x**2 / (a1 + u) + y**2 / (a2 + u) = 1 with some a1 > a2.
The parametrization is given in terms of elliptic functions: ::
x(s1, s2) = k * sqrt(a1 - a2) * sn(s1, k) / sn(s2, k)
y(s1, s2) = sqrt(a1 - a2) * dn(s1, k) * cn(s2, k) / sn(s2, k)
The relation to the parameters `u = u1` (hyperbolas) and `u = u2` (ellipses)
of the confocal system are given by ::
u1(s1) = k**2 * (a1 - a2) * sn(s1)**2 - a1
u2(s2) = (a1 - a2) * ns(s2)**2 - a1
The diagonals `s1 +- s2 = const` lie on lines, which are tangent to a hyperbola.
Along the `s2` direction the parametrization is bounded by this hyperbola,
and geos to infinity in finite time, while it is periodic along the `s1` direction.
The parametrization is closely related to incircular nets (IC-nets):
The straight diagonals of a uniform samlping of this parametrization constitutes
an IC-net.
Parameters
----------
s1 : float
First parameter (fundamental domain: [0, 2K)).
s2 : float
Second parameter (fundamental domain: (0, K)).
a1 : float with a1 > a2
Determines the first semi axis of the conics.
a2 : float with a1 > a2
Determines the second semi axis of the conics.
k : float
Modulus of the elliptic functions (0 < k**2 < 1).
Returns
-------
np.ndarray of shape (2,)
Point in R^2.
"""
def f1(s1, s2, a1, a2, k):
return k * sqrt(a1 - a2) * sn(s1, k) / sn(s2, k)
def f2(s1, s2, a1, a2, k):
return sqrt(a1 - a2) * dn(s1, k) * cn(s2, k) / sn(s2, k)
return np.array([f1(s1, s2, a1, a2, k), f2(s1, s2, a1, a2, k)])
[docs]def confocal_conics_hyperbolic_pencil(s1, s2, a1, a2):
r"""2-dimensional coordinate system along confocal conics (outside a hyperbola) ::
x**2 / (a1 + u) + y**2 / (a2 + u) = 1 with some a1 > a2.
The parametrization is given in terms of elliptic functions: ::
x(s1, s2) = sqrt(a1 - a2) * exp(s1 + s2)
y(s1, s2) = sqrt(a1 - a2) * sqrt((1 - exp(2 * s1)) * (exp(2 * s2) - 1))
The relation to the parameters u = u1 (hyperbolas) and u = u2 (ellipses)
of the confocal system are given by ::
u1(s1) = (a1 - a2) * exp(2*s1) - a1
u2(s2) = (a1 - a2) * exp(2*s2) - a1
The parametrization covers the first quadrant, where the y-axis is approached
in the limit `s1 -> -inf`.
It is diagonally related to vertical lines and to a hyperbolic pencil of circles
which has the two foci of the confocal conics as limiting points:
The diagonals `s1 + s2 = xi = const` lie on vertical lines.
The diagonals `s2 - s1 = eta = const` lie on circles
with center `(sqrt(a1-a2)*cosh(eta),0)` and radius `sqrt(a1-a2)*sinh(eta)`.
Parameters
----------
s1 : float in (-inf, 0)
First parameter.
s2 : float in (0, inf)
Second parameter.
a1 : float with a1 > a2
Determines the first semi axis of the conics.
a2 : float with a1 > a2
Determines the second semi axis of the conics.
Returns
-------
np.ndarray of shape (2,)
Point in R^2.
"""
def f1(s1, s2, a1, a2):
return sqrt(a1 - a2) * exp(s1 + s2)
def f2(s1, s2, a1, a2):
return sqrt(a1 - a2) * sqrt((1 - exp(2 * s1)) * (exp(2 * s2) - 1))
return np.array([f1(s1, s2, a1, a2), f2(s1, s2, a1, a2)])