include ; include ; include ; include ; /************************************************/ /* Parameters */ /************************************************/ /* [Fin Specs] */ fin_height = 51; // 10 inches in mm fin_width = 120; // Width at the base in mm fin_top_withdraw = 10; fin_back_withraw = 20; fin_start_angle = 60; // Angle [Point 0 ] fin_sweep = 25; // Sweep Angle [Point 1] fin_edge_angle = 30; fin_edge_strength = 30; fin_counter_angle = 30; // counter angle [Point 2] fin_counter_strength = 10; // Length [Point 2] // Length at the base in mm fin_base = 114; fin_width_tip = 5; // Width at the tip in mm fin_thickness = 8; // Thickness of the fin in mm fin_end_angle = 110; fin_end_strength = 30; // Back fin_back_height = 30; // Percent height fin_back_widthdraw = 20; // Percent height fin_back_angle = 20; // back angle fin_back_strength=30; /* [Base Specs] */ base_tickness=8; base_extra_thickness=80; /* [Debugging] */ // Showing all layers show_debug_layers = false; // Draw master profile draw_profile = true; // Draw Fin draw_fin = false; /* [Rendering] */ // Rendering parts parts="all"; // [all, top, bottom] // Scaling scale_factor = 1.0; // [0.1:0.1:2] $fn=64; /************************************************/ pt1_x = adj_ang_to_opp(fin_height,fin_sweep)+fin_base/2; pt1_y = fin_height; echo ("counterTop(fin_width,fin_top_withdraw)",counterTop(fin_width,fin_top_withdraw,fin_height)); echo ("handleEnd(fin_width,fin_top_withdraw,fin_counter_angle,fin_counter_strength)",handleEnd(fin_width,fin_top_withdraw,fin_counter_angle,fin_counter_strength)); echo ("xAngleFactor(-20)",xAngleFactor(-20)); echo("polar_to_x : ",polar_to_xy(100, 180)); back_point = [fin_width-7,fin_height/2]; tail_point = [fin_width-3,fin_height/5]; edge_point = [fin_width-fin_top_withdraw,fin_height-2]; counter_edge_point = [fin_width-6,fin_height-8]; control_points = [ // ***************** // INITIAL POINT // ***************** [0,0], // Point 0 [opp_ang_to_adj(fin_height/3,fin_start_angle),fin_height/3], // Handle 0 // ***************** // TOP POINT // ***************** [pt1_x-fin_base/5,pt1_y], // Handle 1 (Start) [pt1_x,pt1_y], // Point 1 [pt1_x+fin_base/7,pt1_y], // Handle 1 (End) // ***************** // EDGE POINT // ***************** //counterTop(fin_width,fin_top_withdraw,fin_height), // [250,220], // Point 2 handle(edge_point,140 /*degree*/,4), edge_point, // [250,220], // Point 2 handle(edge_point,-45 /*degree*/,4), // ***************** // COUNTER EDGE POINT // ***************** //counterTop(fin_width,fin_top_withdraw,fin_height), // [250,220], // Point 2 handle(counter_edge_point,120 /*degree*/,4), counter_edge_point, // [250,220], // Point 2 handle(counter_edge_point,-110 /*degree*/,13), // ***************** // BACK Point // ***************** //counterTop(fin_width,fin_top_withdraw,fin_height), // [250,220], // Point 2 /* handle(back_point,90 ,6), back_point, handle(back_point,-90 ,6), */ // ***************** // TAIL Point // ***************** handle(tail_point,115 ,10), tail_point, //handle(tail_point,-90,10), handle(tail_point,0,0), //tailPoint(), // ***************** // BACK POINT // ***************** /* handle(backPoint(),fin_back_angle,fin_back_strength), backPoint(), handle(backPoint(),-fin_back_angle,fin_back_strength), */ // ***************** // END POINT // ***************** //endHandle(fin_end_angle), // End Handle handle([fin_base,0],60 /*degree*/,3), [fin_base,0] // End point ]; function handle(point,angle,strength) = [ //point[0] + adj_ang_to_opp(strength,angle) /** xAngleFactor(angle)*/, //point[1] + /*(angle>0 ? strength :-strength)*/ strength * yAngleFactor(angle), point[0] + polar_to_xy(strength,angle)[0] , point[1] + polar_to_xy(strength,angle)[1] ]; function xAngleFactor(angle) = angle > 0 && angle < 180 ? 1 : -1; function yAngleFactor(angle) = angle > -90 && angle < 90 ? 1 : -1; function counterTop(x,withdraw,height) = [x-withdraw, height ]; function handleStart(x,withdraw,angle,strength) = [x+adj_ang_to_opp(strength,angle), x-withdraw +strength]; function handleEnd(x,withdraw,angle,strength) = [x-adj_ang_to_opp(strength,angle), x-withdraw -strength]; function endHandle(angle)= angle < 90 ? [fin_base + adj_ang_to_opp(fin_end_strength,90-angle),fin_end_strength] : [fin_base - adj_ang_to_opp(fin_end_strength,angle-90),fin_end_strength] ; function backPoint() = [fin_base-(fin_back_widthdraw/100*fin_base),fin_back_height/100*fin_height]; function decrease_y(points, percentage) = [ for (p = points) [p[0], p[1] * (1 - percentage/100)]]; function pathProfile(points) = bezpath_curve(points,N=3); function remove_last(arr) = select(arr, 0, len(arr) - 2); // Surf Fin profile fin_profile = pathProfile( control_points ); // **************** // * Slicing * // **************** layer_0 = pathProcess(addBase(fin_profile)); // Master layer with base layer_1 = pathProcess(offset(layer_0,delta=-5,chamfer=true)); layer_2 = pathProcess(offset(layer_1,delta=-7,chamfer=false)); layer_3 = pathProcess(offset(layer_2,delta=-5,chamfer=false)); layer_4 = pathProcess(offset(layer_3,delta=-5,chamfer=false)); //echo ("layer_2",layer_2); //echo ("layer_3",layer_3); layers = [layer_0,layer_1,layer_2,layer_3]; function pathProcess(path) = subdivide_path(path,200); function pathProcess3(path) = path; // **************** // * Fin Drawing * // **************** if (draw_fin) { scale([scale_factor, scale_factor, scale_factor]) build(); } module build() { union(){ //cube([50,50,90]); difference(){ union() { if (parts != "bottom") buildFinSide([layer_0,layer_1,layer_2],base_tickness/2); if (parts != "top") zflip() buildFinSide([layer_0,layer_1,layer_2],base_tickness/2); } color("Red") cube([fin_base+20,base_extra_thickness+20,base_tickness+20],anchor=LEFT+BACK); } } } module subtracted(anchor) { color("Red") fwd(40) left(40) cube([fin_width+100,fin_height+100,20],anchor=anchor); } /** * Build fin side * * @param layers - Layers path as array * @param thickness - thickness of half fin */ module buildFinSide(layers,thickness,flip=false) { color("Grey") skin(layers,slices=0,z=layerHeights(len(layers),thickness)); } echo ("layerHeights(3,thickness):",layerHeights(3,base_tickness/2)); if (show_debug_layers) { left(300) { showDebugPath(layer_0); showDebugPath(layer_1); showDebugPath(layer_2); assert(is_path(layer_3),"Layer 3 is not a path"); showDebugPath(layer_3); showDebugPath(layer_4); } //showDebugPath(layer_3); } if (draw_profile) { // Draw fin profile drawProfile( control_points, true ); } /** * 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=1); } /** * Draws a profile based on Bezier path points with optional debug visualization. * * @param points - Array of points defining the Bezier path. * @param debug - Boolean flag to enable/disable debug visualization. Defaults to true. * * This module: * - Calculates the closest point on the Bezier path to a fixed point. * - Draws the Bezier path with debug information if debug is true. * - Optionally shows spheres at specific points for debugging (currently commented out). */ module drawProfile( points,debug = true ){ pt = [100,0]; pos = bezpath_closest_point(points, pt); xy = bezpath_points(points,pos[0],pos[1]); debug_bezier(points, N=3,width=0.2); //color("red") translate(pt) sphere(r=6); //color("blue") translate(xy) sphere(r=6); } /** * Adds a base to the given path by extending it with additional points. * * @param path - The original path to which the base will be added. * @return A new path with an added base. * * This function concatenates: * - The original path (`pathProfile`). * - A point `fin_base` which might represent the start or end of the base. * - Points for additional thickness (`-base_extra_thickness`) at both ends of the base. */ function addBase(path) = concat(path,[[fin_base,-base_extra_thickness],[0,-base_extra_thickness]]); /** * Calculates heights for n layers where the first layer starts at 0 and the last at fin_thickness. * * @param n - Number of layers. * @param fin_thickness - The total height to be divided. * @return An array where each element represents the height of the top of each layer. */ function layerHeights(n, fin_thickness) = let( layer_height = fin_thickness / (n - 1) ) [ for (i = [0 : n-1]) i * layer_height ]; echo ("**********************"); echo ("* Configuration *"); echo ("**********************"); echo ("Layers count" ,len(layers)); echo ("Base thickness" ,str(base_tickness," mm")); echo ("Layers heights" ,layerHeights(len(layers),base_tickness/2));