SurfFins/common.scad

126 lines
2.6 KiB
OpenSCAD

// Constants
// Cooordinates
X=0;
Y=1;
Z=2;
// Offset
OFFSET=0.01;
/**
* Handle for bézier point
*
* @param point - Point to manage
* @param angle - Angle starting as 3h00
* @param strength - Handle distance from manage point
*/
function handle(point,angle,strength) = [
point[0] + polar_to_xy(strength,angle)[0] ,
point[1] + polar_to_xy(strength,angle)[1]
];
/**
* Show Debug point
*/
module debugPoint(point, id, color) {
translate(point) {
color(color) sphere(r = 1.5);
translate([3, 3, 0.6]) {
color("white")
scale([0.2, 0.2, 1])
linear_extrude(height = 0.1)
text(str(id), size = 20, halign = "center", valign = "center");
}
}
}
/**
* 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;