Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def edge_adjust(edge, verts):
if 0 in edge:
return verts
dist = numpy.sqrt(numpy.einsum("ij,ij->i", verts, verts))
return verts / dist[:, None]
def face_adjust(face, bary, verts, corner_verts):
assert face[0] == 0
edge_proj_bary = numpy.array([numpy.zeros(bary.shape[1]), bary[1], bary[2]]) / (
bary[1] + bary[2]
)
edge_proj_cart = numpy.dot(corner_verts.T, edge_proj_bary).T
dist = numpy.sqrt(numpy.einsum("ij,ij->i", edge_proj_cart, edge_proj_cart))
return verts / dist[:, None]
return _compose_from_faces(
corners, faces, n, edge_adjust=edge_adjust, face_adjust=face_adjust
)
def tetra_sphere(n):
corners = numpy.array(
[
[2 * numpy.sqrt(2) / 3, 0.0, -1.0 / 3.0],
[-numpy.sqrt(2) / 3, numpy.sqrt(2.0 / 3.0), -1.0 / 3.0],
[-numpy.sqrt(2) / 3, -numpy.sqrt(2.0 / 3.0), -1.0 / 3.0],
[0.0, 0.0, 1.0],
]
)
faces = [(0, 1, 2), (0, 1, 3), (0, 2, 3), (1, 2, 3)]
vertices, cells = _compose_from_faces(corners, faces, n)
# push all nodes to the sphere
norms = numpy.sqrt(numpy.einsum("ij,ij->i", vertices, vertices))
vertices = (vertices.T / norms.T).T
return vertices, cells
def ngon(p, n, offset=numpy.pi / 2):
k = numpy.arange(p)
corners = numpy.vstack(
[
[[0.0, 0.0]],
numpy.array(
[
numpy.cos(2 * numpy.pi * k / p + offset),
numpy.sin(2 * numpy.pi * k / p + offset),
]
).T,
]
)
faces = [(0, k + 1, k + 2) for k in range(p - 1)] + [[0, p, 1]]
return _compose_from_faces(corners, faces, n)
(11, 10, 2),
(10, 7, 6),
(7, 1, 8),
(3, 9, 4),
(3, 4, 2),
(3, 2, 6),
(3, 6, 8),
(3, 8, 9),
(4, 9, 5),
(2, 4, 11),
(6, 2, 10),
(8, 6, 7),
(9, 8, 1),
]
vertices, cells = _compose_from_faces(corners, faces, n)
# push all nodes to the sphere
norms = numpy.sqrt(numpy.einsum("ij,ij->i", vertices, vertices))
vertices = (vertices.T / norms.T).T
return vertices, cells
[0.0, -1.0, 0.0],
[0.0, 0.0, 1.0],
[0.0, 0.0, -1.0],
]
)
faces = [
(0, 2, 4),
(1, 2, 4),
(1, 3, 4),
(0, 3, 4),
(0, 2, 5),
(1, 2, 5),
(1, 3, 5),
(0, 3, 5),
]
vertices, cells = _compose_from_faces(corners, faces, n)
# push all nodes to the sphere
norms = numpy.sqrt(numpy.einsum("ij,ij->i", vertices, vertices))
vertices = (vertices.T / norms.T).T
return vertices, cells