- Projection and extrusion fixed again

This commit is contained in:
bklronin
2024-07-16 20:11:24 +02:00
parent c6f48a6e78
commit 048ace83ce
3 changed files with 99 additions and 45 deletions

35
main.py
View File

@@ -501,22 +501,37 @@ class Geometry:
return math.sqrt((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2)
def extrude_shape(self, points, length: float, angle, normal, centroid, symet: bool = True, invert: bool = False):
"""2D to 3D sdf always first"""
"""
Extrude a 2D shape into 3D, orient it along the normal, and position it relative to the centroid.
"""
# Normalize the normal vector
normal = np.array(normal)
normal = normal / np.linalg.norm(normal)
# Create the 2D shape
f = polygon(points)
# Extrude the shape along the Z-axis
f = f.extrude(length)
# Calculate the offset vector (half the length in the direction of the normal)
offset = [n * (length / 2) for n in normal]
# Center the shape along its extrusion axis
f = f.translate((0, 0, length / 2))
# Apply the offset in the direction of the normal
f = f.translate(offset)
# Apply the centroid translation
#f = f.translate(centroid)
# Apply the orientation
# Orient the shape along the normal vector
f = f.orient(normal)
# Calculate the current center of the shape
shape_center = [0,0,0]
# Calculate the vector from the shape's center to the centroid
center_to_centroid = np.array(centroid) - np.array(shape_center)
# Project this vector onto the normal to get the required translation along the normal
translation_along_normal = np.dot(center_to_centroid, normal) * normal
# Translate the shape along the normal
f = f.translate(translation_along_normal)
return f
def mirror_body(self, sdf_object3d):