Skip to content

Commit 53a04a1

Browse files
committed
FIX: add axis compatibility for elements with no joints
1 parent 5aa776c commit 53a04a1

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

src/gh/diffCheck/diffCheck/df_geometries.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -467,10 +467,12 @@ def compute_axis(self, is_unitized: bool = True) -> rg.Line:
467467
:return axis: The axis of the beam as a line
468468
"""
469469
joints = self.joints
470-
joint1 = joints[0]
471-
joint2 = joints[1]
472-
max_distance = 0
470+
joint1 = None
471+
joint2 = None
473472
if len(joints) > 2:
473+
joint1 = joints[0]
474+
joint2 = joints[1]
475+
max_distance = 0
474476
for j1 in joints:
475477
for j2 in joints:
476478
distance = rg.Point3d.DistanceTo(
@@ -480,6 +482,22 @@ def compute_axis(self, is_unitized: bool = True) -> rg.Line:
480482
max_distance = distance
481483
joint1 = j1
482484
joint2 = j2
485+
else:
486+
#get the two farthest dffaces for simplicity
487+
df_faces = [face for face in self.faces]
488+
max_distance = 0
489+
for i in range(len(df_faces)):
490+
for j in range(i+1, len(df_faces)):
491+
distance = rg.Point3d.DistanceTo(
492+
df_faces[i].center.to_rg_point3d(),
493+
df_faces[j].center.to_rg_point3d())
494+
if distance > max_distance:
495+
max_distance = distance
496+
joint1 = df_faces[i]
497+
joint2 = df_faces[j]
498+
499+
if joint1 is None or joint2 is None:
500+
raise ValueError("The beam axis cannot be calculated")
483501

484502
axis_ln = rg.Line(
485503
joint1.center.to_rg_point3d(),

0 commit comments

Comments
 (0)