from functools import partial
import numpy as np
import ddg
from ddg.nets._utils import compose
[docs]def jacobi_elliptic_curve(k):
"""Returns the elliptic curve [cn, sn, dn] for a parameter k.
More precisely, returns the collection of curves obtained by first taking
the curve ::
u -> [cn(u, k), sn(u, k), dn(u, k)]
and adding the reflection of this about the plane z = 0. In the case where
k = 1, we also have to reflect about the planes x = 0 and x + z = 0.
This curve (collection) is the intersection of the two cylinders ::
x^2 + y^2 = 1,
k^2 * y^2 + z^2 = 1
Homogenizing in the last component, to [cn, sn, dn, 1], gives the
intersection curve of any two quadrics in the pencil ::
u1 * diag([1, 1, 0, -1]) + u2 * diag([0, k**2, 1, -1])
in homogeneous coordinates.
Parameters
----------
k : float
Parameter in the interval [0, 1]. It is best to avoid values close
(about 1e-9) but not equal to 1 because the scipy.ellipj functions do
not work well for those values.
Returns
-------
NetCollection
"""
curve_fct = partial(ddg.math.parametrizations.elliptic_curve_jacobi, k=k)
domain = ddg.math.parametrizations.elliptic_curve_jacobi_domain(k)
curve = ddg.nets.SmoothNet(curve_fct, domain)
diagonals = [(1, 1, -1)] + ([(-1, 1, 1), (-1, 1, -1)] if k == 1 else [])
curves = [curve] + [compose(np.diag(d), curve) for d in diagonals]
return ddg.nets.NetCollection(curves)