mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-26 10:11:46 +00:00
improved general input calculations
This commit is contained in:
@@ -386,9 +386,15 @@ class PolylineDecorator:
|
|||||||
last_point = Vector((0, 0, 0))
|
last_point = Vector((0, 0, 0))
|
||||||
|
|
||||||
if is_input_on:
|
if is_input_on:
|
||||||
snap_vector = Vector(
|
if cls.use_default_container:
|
||||||
(float(cls.input_panel["X"]), float(cls.input_panel["Y"]), default_container_elevation)
|
print("FOI")
|
||||||
)
|
snap_vector = Vector(
|
||||||
|
(float(cls.input_panel["X"]), float(cls.input_panel["Y"]), default_container_elevation)
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
snap_vector = Vector(
|
||||||
|
(float(cls.input_panel["X"]), float(cls.input_panel["Y"]), float(cls.input_panel["Z"]))
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
if cls.use_default_container:
|
if cls.use_default_container:
|
||||||
snap_vector = Vector((snap_prop.x, snap_prop.y, default_container_elevation))
|
snap_vector = Vector((snap_prop.x, snap_prop.y, default_container_elevation))
|
||||||
@@ -404,7 +410,7 @@ class PolylineDecorator:
|
|||||||
else:
|
else:
|
||||||
# Creates a fake "second to last" point away from the first point but in the same x axis
|
# Creates a fake "second to last" point away from the first point but in the same x axis
|
||||||
# this allows to calculate the angle relative to x axis when there is only one point
|
# this allows to calculate the angle relative to x axis when there is only one point
|
||||||
second_to_last_point = Vector((last_point.x - 1000, last_point.y, last_point.z))
|
second_to_last_point = Vector((last_point.x + 1000, last_point.y, last_point.z))
|
||||||
|
|
||||||
distance = (snap_vector - last_point).length
|
distance = (snap_vector - last_point).length
|
||||||
if distance > 0:
|
if distance > 0:
|
||||||
@@ -475,7 +481,7 @@ class PolylineDecorator:
|
|||||||
snap_prop = context.scene.BIMModelProperties.snap_mouse_point[0]
|
snap_prop = context.scene.BIMModelProperties.snap_mouse_point[0]
|
||||||
snap_vector = Vector((snap_prop.x, snap_prop.y, snap_prop.z))
|
snap_vector = Vector((snap_prop.x, snap_prop.y, snap_prop.z))
|
||||||
last_point = Vector((last_point_data.x, last_point_data.y, last_point_data.z))
|
last_point = Vector((last_point_data.x, last_point_data.y, last_point_data.z))
|
||||||
second_to_last_point = None
|
|
||||||
if len(polyline_data) > 1:
|
if len(polyline_data) > 1:
|
||||||
second_to_last_point_data = polyline_data[len(polyline_data) - 2]
|
second_to_last_point_data = polyline_data[len(polyline_data) - 2]
|
||||||
second_to_last_point = Vector(
|
second_to_last_point = Vector(
|
||||||
@@ -484,23 +490,27 @@ class PolylineDecorator:
|
|||||||
else:
|
else:
|
||||||
# Creates a fake "second to last" point away from the first point but in the same x axis
|
# Creates a fake "second to last" point away from the first point but in the same x axis
|
||||||
# this allows to calculate the angle relative to x axis when there is only one point
|
# this allows to calculate the angle relative to x axis when there is only one point
|
||||||
second_to_last_point = Vector((last_point.x - 10, last_point.y, last_point.z))
|
second_to_last_point = Vector((last_point.x + 1000, last_point.y, last_point.z))
|
||||||
|
|
||||||
distance = float(cls.input_panel["D"])
|
distance = float(cls.input_panel["D"])
|
||||||
|
|
||||||
if distance < 0 or distance > 0:
|
if distance < 0 or distance > 0:
|
||||||
angle_rad = radians(180 - float(cls.input_panel["A"]))
|
new_angle = radians(float(cls.input_panel["A"]))
|
||||||
ref_vec = second_to_last_point - last_point
|
print(cls.input_panel["A"])
|
||||||
dir_vec = last_point - snap_vector
|
# new_angle = radians(30)
|
||||||
|
v1 = second_to_last_point - last_point
|
||||||
|
v2 = last_point - snap_vector
|
||||||
|
|
||||||
rot_axis = ref_vec.cross(dir_vec)
|
# Calculate the axis of rotation
|
||||||
rot_axis.normalize()
|
axis = v1.cross(v2).normalized()
|
||||||
rot_axis = Vector((abs(rot_axis.x), abs(rot_axis.y), abs(rot_axis.z)))
|
|
||||||
|
|
||||||
rot_mat = Matrix.Rotation(angle_rad, 3, rot_axis)
|
|
||||||
|
|
||||||
ref_vec.normalize()
|
# Calculate the rotated vector
|
||||||
coords = ((ref_vec @ rot_mat) * distance) + last_point
|
# rotated_vector = v2 * math.cos(new_angle) + axis * math.sin(new_angle) * v1.length + v1 * (1 - math.cos(new_angle)) * (dot_product / v1.length**2)
|
||||||
|
# dir_vec = snap_vector - last_point
|
||||||
|
# coords = dir_vec.normalized() * distance + last_point
|
||||||
|
rot_mat = Matrix.Rotation(new_angle, 3, axis)
|
||||||
|
coords = (v1.normalized() @ rot_mat) * distance + last_point
|
||||||
|
|
||||||
x = coords[0]
|
x = coords[0]
|
||||||
y = coords[1]
|
y = coords[1]
|
||||||
@@ -511,6 +521,7 @@ class PolylineDecorator:
|
|||||||
if "Z" in list(cls.input_panel.keys()):
|
if "Z" in list(cls.input_panel.keys()):
|
||||||
cls.input_panel["Z"] = str(round(z, 3))
|
cls.input_panel["Z"] = str(round(z, 3))
|
||||||
|
|
||||||
|
print(cls.input_panel)
|
||||||
return cls.input_panel
|
return cls.input_panel
|
||||||
|
|
||||||
return cls.input_panel
|
return cls.input_panel
|
||||||
|
|||||||
@@ -91,25 +91,21 @@ class Cad:
|
|||||||
< returns the potentially signed angle as degrees or radians
|
< returns the potentially signed angle as degrees or radians
|
||||||
"""
|
"""
|
||||||
d1 = v1 - v2
|
d1 = v1 - v2
|
||||||
d2 = v2 - v3
|
d2 = v3 - v2
|
||||||
|
|
||||||
axis = d1.cross(d2)
|
axis = d1.cross(d2)
|
||||||
axis.normalize()
|
axis.normalize()
|
||||||
axis = Vector((abs(axis.x), abs(axis.y), abs(axis.z)))
|
|
||||||
|
|
||||||
rotation_axis = d1.cross(d2)
|
# Calculate the unsigned angle between the "d1" and "d2" vectors
|
||||||
|
|
||||||
# Calculate the unsigned angle between the "from" and "to" vectors
|
|
||||||
a = d1.angle(d2)
|
a = d1.angle(d2)
|
||||||
|
|
||||||
|
|
||||||
# Determine the sign of the angle based on the provided axis
|
# Determine the sign of the angle based on the provided axis
|
||||||
|
parameter = axis.z < 0
|
||||||
|
sign = -1 if parameter <= 0 else 1
|
||||||
|
|
||||||
if degrees:
|
if degrees:
|
||||||
a = math.degrees(a)
|
a = math.degrees(a)
|
||||||
|
|
||||||
parameter = rotation_axis.dot(axis)
|
|
||||||
|
|
||||||
sign = 1 if parameter <= 0 else -1
|
|
||||||
|
|
||||||
return a * sign
|
return a * sign
|
||||||
else:
|
else:
|
||||||
return a
|
return a
|
||||||
|
|||||||
Reference in New Issue
Block a user