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

import ddg
from ddg.conversion.nets.geometry.quadrics import quadric_to_smooth_net
from ddg.geometry import euclidean_models
from ddg.geometry.spheres import QuadricSphere
from ddg.nets.parametrizations.spheres_and_circles import circle, sphere


[docs]def sphere_to_smooth_net(sphere): """Sphere to smooth net dispatcher. Parameters ---------- sphere : Euclidean sphere or any QuadricSphere Returns ------- SmoothNet Raises ------ NotImplementedError If type of sphere is not recognized. """ if isinstance(sphere.geometry, euclidean_models.ProjectiveModel): if sphere.dimension == 1: return euclidean_circle_to_smooth_net(sphere) elif sphere.dimension == 2: return euclidean_sphere_to_smooth_net(sphere) if isinstance(sphere, QuadricSphere): return quadric_to_smooth_net(sphere.quadric(), affine=True) raise NotImplementedError( f"Sphere of type {type(sphere)} with geometry {sphere.geometry!r} " f"could not be converted to smooth net." )
[docs]def euclidean_sphere_to_smooth_net(s): """ 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.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(): center = s.center.affine_point 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" "Sphere must be 2-dimensional in 3-dimensional space." )
[docs]def euclidean_circle_to_smooth_net(c): """ 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.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. """ if c.is_circle(): radius = c.radius if not c.center.at_infinity(): center = c.center.affine_point 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=ddg.geometry.normals(c.subspace) ) else: raise ValueError( f"Not a circle. Can not convert a {c.dimension}-dimensional sphere." )