Skip to content

Commit af989eb

Browse files
feat: add a plane property to beams, automatically computed and with the longest axis of the beam as x and normal of the largest face as y
1 parent b2a10b3 commit af989eb

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

src/gh/diffCheck/diffCheck/df_geometries.py

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -516,25 +516,17 @@ def compute_axis(self, is_unitized: bool = True) -> rg.Line:
516516

517517
def compute_plane(self) -> rg.Plane:
518518
"""
519-
This function computes the plane of the beam based on its axis and the first joint's center.
520-
The plane is oriented along the beam's axis.
519+
This is an utility function that computes the plane of the beam.
520+
The plane is calculated using the beam's axis and the world Z axis.
521521
522522
:return plane: The plane of the beam
523523
"""
524-
if not self.joints:
525-
raise ValueError("The beam has no joints to compute a plane")
524+
beam_direction = self.axis.Direction
525+
df_faces = [face for face in self.faces]
526+
sorted_df_faces = sorted(df_faces, key=lambda face: Rhino.Geometry.AreaMassProperties.Compute(face._rh_brepface).Area if face._rh_brepface else 0, reverse=True)
527+
largest_side_face_normal = sorted_df_faces[0].normal
526528

527-
#main axis as defined above
528-
main_direction = self.compute_axis().Direction
529-
530-
#secondary axis as normal to the largest face of the beam
531-
largest_face = max(self.faces, key=lambda f: f.area)
532-
secondary_axis = largest_face.normal
533-
secondary_vector = rg.Vector3d(secondary_axis[0], secondary_axis[1], secondary_axis[2])
534-
first_vector = rg.Vector3d.CrossProduct(main_direction, secondary_vector)
535-
origin = self.center
536-
537-
return rg.Plane(origin, first_vector, secondary_vector)
529+
return rg.Plane(self.center, beam_direction, rg.Vector3d(largest_side_face_normal[0], largest_side_face_normal[1], largest_side_face_normal[2]))
538530

539531
def compute_joint_distances_to_midpoint(self) -> typing.List[float]:
540532
"""
@@ -696,6 +688,11 @@ def axis(self):
696688
self._axis = self.compute_axis()
697689
return self._axis
698690

691+
@property
692+
def plane(self):
693+
self._plane = self.compute_plane()
694+
return self._plane
695+
699696
@property
700697
def length(self):
701698
self._length = self._axis.Length

0 commit comments

Comments
 (0)