WIP: Changed coordinates, distance and angles calculations to allow for 3d vectors

This commit is contained in:
Bruno Perdigão
2024-08-13 17:35:36 -03:00
committed by Bruno Perdigão
parent b137197586
commit 315b6060b0
2 changed files with 20 additions and 8 deletions
@@ -343,14 +343,6 @@ class WallPolylineDecorator:
@classmethod
def calculate_distance_and_angle(cls, context, is_input_on):
def calculate_angle(snap_vector, last_point, second_to_last_point):
v1 = snap_vector - last_point
v2 = last_point - second_to_last_point
cos_angle = (v1.dot(v2)) / (v1.length * v2.length)
if cos_angle > 1:
cos_angle = 1
angle = acos(cos_angle)
return degrees(angle)
try:
polyline_data = context.scene.BIMModelProperties.polyline_point
+20
View File
@@ -84,6 +84,26 @@ class Cad:
a = (edge1[1] - edge1[0]).angle(edge2[1] - edge2[0])
return math.degrees(a) if degrees else a
@classmethod
def angle_3_vectors(cls, v1, v2, v3, degrees=False):
"""
> takes 3 vectors. The order matters, v2 is the center point.
< returns the potentially signed angle as degrees or radians
"""
d1 = v1 - v2
d2 = v2 - v3
cos_a = (d1.dot(d2)) / (d1.length * d2.length)
cos_a = max(-1, min(1, cos_a))
print(v1, v2, v3)
print(cos_a)
a = math.acos(cos_a)
if degrees:
return math.degrees(a)
else:
return a
@classmethod
def is_x(cls, value: float, x: float, tolerance: float | None = None) -> bool:
"""