- Basic 2D projection

This commit is contained in:
bklronin
2024-07-08 22:14:25 +02:00
parent 9daf263aad
commit 5ff48c0f5e
16 changed files with 967 additions and 826 deletions

View File

@@ -2,6 +2,7 @@ import math
import re
from copy import copy
import numpy as np
from PySide6.QtWidgets import QApplication, QWidget, QMessageBox, QInputDialog
from PySide6.QtGui import QPainter, QPen, QColor
from PySide6.QtCore import Qt, QPoint, QPointF, Signal
@@ -47,6 +48,81 @@ class SketchWidget(QWidget):
def create_workplane(self):
self.wp = self.solv.create_2d_base()
def create_workplane_projected(self):
self.wp = self.solv.create_2d_base()
def create_proj_lines(self, lines):
"""Lines as orientation projected from the sketch"""
for line in lines:
for point in line:
x, y, z = point
point = self.solv.add_point_2d(x, y, self.wp)
relation_point = {} # Reinitialize the dictionary
handle_nr = self.get_handle_nr(str(point))
relation_point['handle_nr'] = handle_nr
relation_point['solv_handle'] = point
relation_point['ui_point'] = QPoint(x, y)
self.slv_points_main.append(relation_point)
print("points", self.slv_points_main)
print("lines", self.slv_lines_main)
print("lines", lines)
def find_duplicate_points_2d(self, edges):
points = []
seen = set()
duplicates = []
for edge in edges:
for point in edge:
# Extract only x and y coordinates
point_2d = (point[0], point[1])
if point_2d in seen:
if point_2d not in duplicates:
duplicates.append(point_2d)
else:
seen.add(point_2d)
points.append(point_2d)
return duplicates
def normal_to_quaternion(self, normal):
normal = np.array(normal)
#normal = normal / np.linalg.norm(normal)
axis = np.cross([0, 0, 1], normal)
if np.allclose(axis, 0):
axis = np.array([1, 0, 0])
else:
axis = axis / np.linalg.norm(axis) # Normalize the axis
angle = np.arccos(np.dot([0, 0, 1], normal))
qw = np.cos(angle / 2)
sin_half_angle = np.sin(angle / 2)
qx, qy, qz = axis * sin_half_angle # This will now work correctly
return qw, qx, qy, qz
def create_workplane_space(self, points, normal):
print("edges", points)
origin = self.find_duplicate_points_2d(points)
print(origin)
x, y = origin[0]
origin = QPoint(x, y)
origin_handle = self.get_handle_from_ui_point(origin)
qw, qx, qy, qz = self.normal_to_quaternion(normal)
slv_normal = self.solv.add_normal_3d(qw, qx, qy, qz)
self.wp = self.solv.add_work_plane(origin_handle, slv_normal)
print(self.wp)
def get_handle_nr(self, input_str: str) -> int:
# Define the regex pattern to extract the handle number
pattern = r"handle=(\d+)"