The suspension.py
file contains an algorithm for creating a suspension system from linear elements in Grasshopper/Rhino. The algorithm is designed for automatic generation of suspension structure taking into account geometric constraints and parameters.
Version: v0.06
sort_lines_perpendicular(lines, reference_direction)
Sorts lines perpendicular to a given direction.
Parameters:
lines
- list of lines to sortreference_direction
- reference direction (Vector3d)Returns: sorted list of lines
line_same_direction(lines)
Aligns all lines in the same direction and sorts them perpendicularly.
Parameters:
lines
- list of linesReturns: tuple (sorted lines, reference direction)
suspension_corners(lines, dir, round, min_val, is_start)
Generates suspension corner points taking into account rounding and minimum distance.
Parameters:
lines
- list of linesdir
- directionround
- rounding radiusmin_val
- minimum distanceis_start
- whether these are starting points (True/False)Returns: list of corner points
strict_cluster_points(points, direction, max_distance, is_start=True)
Groups points into clusters based on projection onto a given direction.
Parameters:
points
- list of pointsdirection
- direction for projectionmax_distance
- maximum distance between points in a clusteris_start
- whether these are starting pointsReturns: tuple (group indices, representative points)
project_points_to_group_scalar(points, group_ids, representative_points, direction)
Projects points to their group representative points along a given direction.
Parameters:
points
- list of pointsgroup_ids
- group indices for each pointrepresentative_points
- representative points of groupsdirection
- projection directionReturns: list of aligned points
grouped_polylines_by_index(points, group_indices)
Creates polylines from points based on their group indices.
Parameters:
points
- list of pointsgroup_indices
- group indicesReturns: tuple (polylines, individual points, one point for each group)
connect_point_pairs(start_points, end_points)
Creates lines between pairs of starting and ending points.
Parameters:
start_points
- starting pointsend_points
- ending pointsReturns: list of lines
generate_crossbars_points(lines, max_step, group_points=None)
Generates points for cross elements with uniform step. Supports two operation modes: using group points to determine projection range or classic mode.
Parameters:
lines
- list of linesmax_step
- maximum step between cross elementsgroup_points
- optional list of group points to determine projection rangeReturns: list of point lists for cross elements
remove_duplicate_points(points, min_distance=GLOBAL_TOL)
Removes duplicate points that are closer than min_distance
.
Parameters:
points
- list of pointsmin_distance
- minimum distance between points (default GLOBAL_TOL)Returns: list of unique points
build_segmented_lines(crossbars_points, max_distance)
Creates segmented lines from cross element points.
Parameters:
crossbars_points
- cross element pointsmax_distance
- maximum distance between points in a segmentReturns: tuple (segmented lines, individual points)
polylines_to_lines(poly_curves)
Converts polylines to simple lines.
Parameters:
poly_curves
- list of polylinesReturns: list of lines
match_support_to_boundary(support_lines, boundary_lines, direction, threshold)
Matches support lines with boundary lines based on projection.
Parameters:
support_lines
- support linesboundary_lines
- boundary linesdirection
- direction for projectionthreshold
- distance threshold for matchingReturns: list of group indices for support lines
move_line_to_match_projection(source_line, target_line, direction)
Moves a line to match the projection of the target line.
Parameters:
source_line
- source linetarget_line
- target linedirection
- projection directionReturns: moved line
filter_and_align_lines(boundary_lines, support_lines, support_indices, direction)
Filters and aligns lines based on their matching. Selects the longest line in each group and aligns support lines with boundary lines.
Parameters:
boundary_lines
- boundary linessupport_lines
- support linessupport_indices
- matching indicesdirection
- alignment directionReturns: tuple (filtered boundary lines, filtered support lines)
generate_points_on_lines(lines, step)
Creates points on lines with a given step.
Parameters:
lines
- list of linesstep
- step between pointsReturns: list of points on lines
merge_lines_by_distance(lines, max_distance, length_tolerance=GLOBAL_TOL)
Combines lines that are within a given distance and have the same length.
Algorithm:
Parameters:
lines
- list of lines to combinemax_distance
- maximum distance for combinationlength_tolerance
- allowable difference in line length for combination (default GLOBAL_TOL)Returns: list of combined lines
Note: The function combines only those lines that are within max_distance
of each other and have the same length (with tolerance length_tolerance
). This helps reduce the number of duplicate elements in the suspension system.
GLOBAL_TOL = 0.01
- global tolerance for distance comparisonsLINES
- input lines for processingROUNDING
- corner rounding radiusMIN_DISTANCE_CORNER
- minimum distance for cornersMAX_DISTANCE_CORNER
- maximum distance for grouping corners (intersection points)SUSPENSION_STEP
- step between cross elementsMAX_DIST_B_PT_CENTER
- maximum distance between points in the center when building suspension linesTHRESHOLD_FILTER
- threshold for filtering lines (two types: those at corners and in the center)RODS_STEP
- step between points for rodsDISTANCE_JOINING_START_END_LINES
- maximum distance for combining starting and ending linesNote: ROUNDING
+ MIN_DISTANCE_CORNER
= equals the offset from corners
unistrut_lines
- all suspension lines (boundary + support)boundary_lines_filtered
- filtered boundary linessafe_support_lines_filtered
- filtered support linesrods_points
- points for rods on all suspension linessingle_rods_points
- individual points that do not form lines:
start_lonely
- points at the beginning of a lineend_lonely
- points at the end of a lineorphaned_points
- points in the middle of linesDISTANCE_JOINING_START_END_LINES
and have the same lengthgenerate_crossbars_points
function with group point supportremove_duplicate_points
function for duplicate removalgenerate_points_on_lines
function for creating rod pointsmerge_lines_by_distance
function for combining lines by distance and length