import ddg
[docs]def sphere_to_icosphere(sphere, subdivision_steps=4):
"""
Converts a two-dimensional sphere in three-dimensional ambient
space to a primitive half-edge surface.
Parameters
----------
sphere : ddg.Sphere
A two-dimensional sphere in three-dimensional projective
space.
subdivision_steps : int (default=4)
Number of subdivisions performed.
Returns
-------
icosphere : ddg.halfedge.Surface
Raises
------
ValueError
If the given sphere is not a 2-sphere in three
dimensional projective space.
NotImplementedError
If the center of the sphere is a point at infinity.
"""
if sphere.dimension == 2 and sphere.ambient_dimension == 3:
icosphere = ddg.halfedge.icosphere(subdivision_steps, radius=sphere.radius)
if not sphere.center.at_infinity():
c = sphere.center.affine_point
for v in icosphere.verts:
v.co += c
else:
raise NotImplementedError(
"Can not convert a sphere with center at infinity."
)
return icosphere
else:
raise ValueError(
f"Can not convert a {sphere.dimension}-dimensional sphere "
f"in {sphere.ambient_dimension}-dimensional ambient space.\n"
"Sphere must be 2-dimensional in 3-dimensional space."
)
[docs]def circle_to_halfedge(circle, subdivision_steps=20, co_attr="co"):
"""
Converts a circle in three-dimensional space to
a half-edge surface.
Parameters
----------
circle : ddg.Sphere
A one-dimensional sphere in three-dimensional
projective space.
subdivision_steps : int (default=20)
Number of subdivisions performed.
co_attr : string (default='co')
Name of the vertex attribute that stores the circle
coordinates.
Returns
-------
ddg.halfedge.Surface
Raises
------
ValueError
If the given sphere is not a circle in three
dimensional projective space.
NotImplementedError
If the center of the circle is a point at infinity.
"""
if circle.is_circle() and circle.ambient_dimension == 3:
if circle.center.at_infinity():
raise NotImplementedError(
"Can not convert a circle with center at infinity."
)
else:
center = circle.center.affine_point
return ddg.halfedge.disc(
circle_subdivisions=subdivision_steps,
fill_face=False,
radius=circle.radius,
center=center,
normal=circle.subspace.dual().affine_points,
co_attr=co_attr,
)
else:
raise ValueError(
f"Can not convert a {circle.dimension}-dimensional sphere "
f"in {circle.ambient_dimension}-dimensional ambient space.\n"
"Sphere must be a 1-dimensional circle in 3-dimensional space."
)