Skip to content

Commit

Permalink
remove cylinder expand
Browse files Browse the repository at this point in the history
vedo can do this - will just have to give individual lines
TODO - add connec.individualize_edges()
  • Loading branch information
j042 committed Feb 29, 2024
1 parent 271cab8 commit db0ce3a
Showing 1 changed file with 0 additions and 99 deletions.
99 changes: 0 additions & 99 deletions gustaf/create/faces.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,105 +245,6 @@ def edges_as_quad(edges, scaled_normals):
return Faces(vertices, quad)


def _two_ortho(derivative, second_derivative=None):
"""
Finds two orthogonal vectors to derivative.
Without second derivatives,
it doesn't work if the vector is multiples of [-1, 1, -1].
"""
if second_derivative is None:
aux = np.empty_like(derivative)
aux[:, 0] = -derivative[:, 2]
aux[:, [1, 2]] = derivative[:, [0, 1]]
else:
# normalized_second_der / its_norm
aux = second_derivative / np.linalg.norm(
second_derivative, axis=1
).reshape(-1, 1)

# cross and normalize
o1 = utils.arr.cross3d(derivative, aux)
norm_inv = np.linalg.norm(o1, axis=1)
np.reciprocal(norm_inv, out=norm_inv)
np.multiply(o1, norm_inv.reshape(-1, 1), out=o1)

# cross and normalize
o2 = utils.arr.cross3d(derivative, o1)
norm_inv = np.linalg.norm(o2, axis=1)
np.reciprocal(norm_inv, out=norm_inv)
np.multiply(o2, norm_inv.reshape(-1, 1), out=o2)

return o1, o2


def _circle_sample(centers, r, o1, o2, resolution):
"""given two orthogonal vectors, this samples a circle on that plane"""
o_shape = o1.shape

cir = np.empty((resolution * o_shape[0], o_shape[1]))

q = np.linspace(0, 2 * np.pi, resolution + 1)[:-1]

cos = np.cos(q)
sin = np.sin(q)

for i, (c, s) in enumerate(zip(cos, sin)):
cir[i::resolution] = centers + (r * c * o1) + (r * s * o2)

return cir


def edges_as_cylinder(
edges, r, derivative, second_derivative=None, resolution=10
):
"""
Turns edges into cylinder.
Edges should be in 3D and works best,
if second derivative of the vertices are given.
Parameters
----------
edges: Edges
Edges with `n` vertices
r: float
Radius of the cylinder
derivative: (n, 3) np.ndarray
second_derivative: (n, 3) np.ndarray
(Optional)
resolution: int
resolution of cylinder
Returns
-------
as_cylinder: Faces
This has open caps.
"""
vertices = _circle_sample(
edges.vertices,
r,
*_two_ortho(derivative, second_derivative),
resolution,
)

e = edges.edges * resolution
flip_e = e[:, [1, 0]]

quads = np.empty(
(len(edges.edges) * resolution, 4), dtype=settings.INT_DTYPE
)
quads[::resolution, [0, 1]] = e
quads[::resolution, [2, 3]] = flip_e + 1
for i in range(1, resolution - 1):
# offset_i = offset * i
quads[i::resolution, [0, 1]] = e + i
quads[i::resolution, [2, 3]] = flip_e + (i + 1)

quads[(resolution - 1) :: resolution, [0, 1]] = e + (resolution - 1)
quads[(resolution - 1) :: resolution, [2, 3]] = flip_e

return Faces(vertices, quads)


def vertex_normals(
faces,
area_weighting=False,
Expand Down

0 comments on commit db0ce3a

Please sign in to comment.