Source code for ddg.conversion.nets.geometry.spheres

from ddg.datastructures.nets.net_generators.spheres_and_circles import sphere, circle
import ddg.geometry.subspaces as subspaces
from ddg.geometry.geometries import EuclideanGeometry
from ddg.geometry.conversion import cayley_klein_sphere_to_quadric
from ddg.conversion.nets.geometry.quadrics import quadric_to_smooth_net


[docs]def sphere_to_smooth_net(sphere, affine_component=-1): ac = affine_component if not isinstance(sphere.geometry, EuclideanGeometry): return cayley_klein_sphere_to_smooth_net(sphere, affine_component=ac) if sphere.is_circle(): return euclidean_circle_to_smooth_net(sphere, affine_component=ac) else: return euclidean_sphere_to_smooth_net(sphere, affine_component=ac)
[docs]def euclidean_sphere_to_smooth_net(s, affine_component=-1): """ Converts a two-dimensional sphere in three-dimensional ambient space to a smooth net. Parameters ---------- s : ddg.Sphere A two-dimensional sphere in three-dimensional projective space. Returns ------- ddg.datastructures.nets.SmoothNet A parameter-dependent smooth net. Raises ------ ValueError If the given sphere is not a two-dimensional sphere in three-dimensional projective space. NotImplementedError If center of the sphere is a point at infinity. Notes ----- The resulting SmoothNet object depends the radius and the center of the sphere as parameters. """ if s.dimension == 2 and s.ambient_dimension == 3: radius = s.radius if not s.center.at_infinity(affine_component): center = s.center.affine_point(affine_component) else: raise NotImplementedError("Can not convert a sphere with " "center at infinity.") return sphere(center=center, radius=radius) else: raise ValueError(f"Can not convert a {s.dimension}-dimensional sphere " f"in {s.ambient_dimension}-dimensional ambient space.\n" f"Sphere must be 2-dimensional in 3-dimensional space.")
[docs]def euclidean_circle_to_smooth_net(c, affine_component=-1): """ Converts a circle in n-dimensional space to a smooth curve. Parameters ---------- c : ddg.Sphere A one-dimensional sphere in n-dimensional projective space. Returns ------- ddg.datastructures.nets.SmoothCurve A parameter-dependent smooth curve. Raises ------ ValueError If the given sphere is not a circle in n-dimensional projective space. NotImplementedError If center of the circle is a point at infinity. Notes ----- The resulting SmoothCurve object depends on the following parameters: the radius of the circle, the center of the circle and optionally (if the ambient dimension is greater than 2) the normals of its defining plane. """ i = affine_component if c.is_circle(): radius = c.radius if not c.center.at_infinity(i): center = c.center.affine_point(i) else: raise NotImplementedError("Can not convert a circle with " "center at infinity.") if c.subspace.codimension == 0: return circle(center=center, radius=radius) else: return circle(center=center, radius=radius, normals=subspaces.normals(c.subspace, i)) else: raise ValueError(f"Not a circle. Can not convert a {c.dimension}-" f"dimensional sphere.")
[docs]def cayley_klein_sphere_to_smooth_net(sphere, affine_component=-1): """Convert Cayley-Klein sphere to smooth net. This function works by first converting the sphere to a quadric and then using quadric_to_smooth_net. For this to work, the sphere's geometry must implement metric_to_cayley_klein_distance and the resulting quadric type must be convertible to a smooth net. Parameters ---------- sphere : Sphere affine_component: int (default=-1) Returns ------- SmoothNet """ ac = affine_component Q = cayley_klein_sphere_to_quadric(sphere) return quadric_to_smooth_net(Q, affine=True, affine_component=ac)