- More projection and extrusion in place

This commit is contained in:
bklronin
2024-07-10 23:19:43 +02:00
parent b5c965bf2e
commit cb471b4108
4 changed files with 185 additions and 90 deletions

53
main.py
View File

@@ -295,7 +295,20 @@ class MainWindow(QMainWindow):
#Create and draw Interactor
geo = Geometry()
f = geo.extrude_shape(points, length)
# Get the nromal form the 3d widget for extrusion
if self.custom_3D_Widget.selected_normal is not None:
normal = self.custom_3D_Widget.selected_normal.tolist()
print("normal", normal)
angle = geo.angle_between_normals([0, 1, 0], normal)
print("Angle", angle)
f = geo.extrude_shape(points, length, angle, normal)
f = geo.mirror_body(f)
else:
normal = [0,0,-1]
angle = 0
f = geo.extrude_shape(points, length, angle, normal)
name_op = f"extrd-{name}"
element = {
@@ -316,7 +329,6 @@ class MainWindow(QMainWindow):
name = self.ui.body_list.currentItem().text()
points = self.model['operation'][name]['sdf_object']
self.list_selected.append(points)
#print(self.list_selected)
if len(self.list_selected) > 1:
geo = Geometry()
@@ -332,8 +344,8 @@ class MainWindow(QMainWindow):
self.model['operation'][name_op] = element
self.ui.body_list.addItem(name_op)
items = self.ui.sketch_list.findItems(name_op, Qt.MatchExactly)
self.ui.body_list.setCurrentItem(items[-1])
#self.draw_mesh()
#self.ui.body_list.setCurrentItem(items[-1])
self.draw_mesh()
else:
print("mindestens 2!")
@@ -342,17 +354,46 @@ class MainWindow(QMainWindow):
self.custom_3D_Widget.update()
class Geometry:
def angle_between_normals(self, normal1, normal2):
# Ensure the vectors are normalized
n1 = normal1 / np.linalg.norm(normal1)
n2 = normal2 / np.linalg.norm(normal2)
# Compute the dot product
dot_product = np.dot(n1, n2)
# Clip the dot product to the valid range [-1, 1]
dot_product = np.clip(dot_product, -1.0, 1.0)
# Compute the angle in radians
angle_rad = np.arccos(dot_product)
# Convert to degrees if needed
angle_deg = np.degrees(angle_rad)
print("Angle deg", angle_deg)
return angle_rad
def distance(self, p1, p2):
"""Calculate the distance between two points."""
print("p1", p1)
print("p2", p2)
return math.sqrt((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2)
def extrude_shape(self, points, length: float):
def extrude_shape(self, points, length: float, angle, normal):
"""2D to 3D sdf always first"""
f = polygon(points).extrude(length)
f = polygon(points).rotate(angle)
f = f.extrude(length).orient(normal) # orient(normal)
return f
def mirror_body(self, sdf_object3d):
f = sdf_object3d.rotate(pi)
return f
def cut_shapes(self, sdf_object1, sdf_object2):
f = difference(sdf_object1, sdf_object2) # equivalent
return f