diff --git a/common.scad b/common.scad index 95e6b10..18c630f 100644 --- a/common.scad +++ b/common.scad @@ -12,7 +12,7 @@ Z=2; OFFSET=0.01; -/* +/** * Handle for bézier point * * @param point - Point to manage @@ -27,7 +27,9 @@ function handle(point,angle,strength) = [ - +/** + * Show Debug point + */ module debugPoint(point, id, color) { translate(point) { color(color) sphere(r = 1.5); @@ -40,3 +42,84 @@ module debugPoint(point, id, color) { } } } + +/** + * Displays debug information for a path by visualizing its self-crossings. + * + * @param path - The input path to analyze for self-crossings. + * + * This module: + * - Splits the path at points where it intersects itself. + * - Renders each segment of the split path with different colors for easy identification. + */ +module showDebugPath(path) { + assert(is_path(path),"Path to show is not a path"); + assert(is_path_simple(path),"Path is not simple"); + rainbow(split_path_at_self_crossings(path)) + stroke($item, closed=false, width=0.2); +} + + +/** + * Rounded Triangle + */ +module rounded_triangle(radius, height) { + triangle_points = [[0, 0], [75, 0], [0, -35]]; // Equilateral triangle with side length 100 + rounded_shape = round_corners( triangle_points, r=radius ); + mirror([0,0,1]) linear_extrude(height = height) polygon(rounded_shape); +} + + +/** + * Function to translate a path manually along X and Y + * + * @param path - Original path + * @param dx - x translation + * @param dy - y translation + */ +function translate_path(path, dx=0, dy=0) = [for (p = path) [p[0] + dx, p[1] + dy]]; + + +/** + * Convert points to bezier curve + * + * @param points - Points + */ +function asCurve( points ) = bezpath_curve(points,N=3,splinesteps=64); + + + +//function asCurve2( points ) = path_to_bezpath(bezier_curve(points,splinesteps=64)); + +//path_to_bezpath + +/** + * Print path points + */ +module print_path_points(path) { + for (i = [0:len(path)-1]) { + echo(str("\t Point ", i, ": [", path[i][0], ", ", path[i][1], "]")); + } +} + +/** + * Expand path + * + * @param path - Original path + * param delta - distance to expand + */ +function expandPath(path,delta) = + offset( + deduplicate(path), + delta=delta, + chamfer=false, + same_length=true + ) + ; + + +/** + * Inches to centimeter conversion + */ +function inches_to_cm(inches) = inches * 2.54; +