diff --git a/docs/lib3x-path_scaling_sections.md b/docs/lib3x-path_scaling_sections.md index 8e859e5c..420c712e 100644 --- a/docs/lib3x-path_scaling_sections.md +++ b/docs/lib3x-path_scaling_sections.md @@ -67,7 +67,7 @@ You can use any point as the first point of the edge path. Just remember that yo use ; use ; use ; - use ; + use ; taiwan = shape_taiwan(100); fst_pt = [13, 0, 0]; @@ -91,7 +91,7 @@ You can use any point as the first point of the edge path. Just remember that yo for(i = [0:leng - 1]) [ for(p = sections[i]) - rotate_p(p, twist_step * i) + ptf_rotate(p, twist_step * i) ] ]; @@ -103,7 +103,7 @@ You can use any point as the first point of the edge path. Just remember that yo use ; use ; use ; - use ; + use ; taiwan = shape_taiwan(100); @@ -115,12 +115,12 @@ You can use any point as the first point of the edge path. Just remember that yo a = atan2(fst_pt[1], fst_pt[0]); edge_path = [ fst_pt, - fst_pt + rotate_p([0, 0, 10], a), - fst_pt + rotate_p([10, 0, 20], a), - fst_pt + rotate_p([8, 0, 30], a), - fst_pt + rotate_p([10, 0, 40], a), - fst_pt + rotate_p([0, 0, 50], a), - fst_pt + rotate_p([0, 0, 60], a) + fst_pt + ptf_rotate([0, 0, 10], a), + fst_pt + ptf_rotate([10, 0, 20], a), + fst_pt + ptf_rotate([8, 0, 30], a), + fst_pt + ptf_rotate([10, 0, 40], a), + fst_pt + ptf_rotate([0, 0, 50], a), + fst_pt + ptf_rotate([0, 0, 60], a) ]; #hull_polyline3d(edge_path); diff --git a/docs/lib3x-rail_extruded_sections.md b/docs/lib3x-rail_extruded_sections.md new file mode 100644 index 00000000..e84206f7 --- /dev/null +++ b/docs/lib3x-rail_extruded_sections.md @@ -0,0 +1,127 @@ +# rail_extruded_sections + +Given a rail with the first point at the outline of a shape. This function uses the rail to extrude the shape and returns all sections in the reversed order of the rail. Combined with the `sweep` module, you can create rail extrusion. + +In order to control extrusion easily, I suggest using `[x, 0, 0]` as the first point and keeping y = 0 while building the rail. + +**Since:** 3.2 + +## Parameters + +- `shape_pts` : A list of points represent a shape. +- `rail` : A list of points represent the edge path. + +## Examples + + use ; + use ; + use ; + use ; + + taiwan = shape_taiwan(100); + fst_pt = [13, 0, 0]; + + rail = [ + fst_pt, + fst_pt + [0, 0, 10], + fst_pt + [10, 0, 20], + fst_pt + [8, 0, 30], + fst_pt + [12, 0, 40], + fst_pt + [0, 0, 50], + fst_pt + [0, 0, 60] + ]; + + #hull_polyline3d(rail); + sweep(rail_extruded_sections(taiwan, rail)); + +![rail_extruded_sections](images/lib3x-rail_extruded_sections-1.JPG) + + use ; + use ; + use ; + use ; + use ; + + + taiwan = shape_taiwan(100); + fst_pt = [13, 0, 0]; + + rail = bezier_curve(0.05, [ + fst_pt, + fst_pt + [0, 0, 10], + fst_pt + [10, 0, 20], + fst_pt + [8, 0, 30], + fst_pt + [12, 0, 40], + fst_pt + [0, 0, 50], + fst_pt + [0, 0, 60] + ]); + + #hull_polyline3d(rail); + sweep(rail_extruded_sections(taiwan, rail)); + +![rail_extruded_sections](images/lib3x-rail_extruded_sections-2.JPG) + + use ; + use ; + use ; + use ; + use ; + + taiwan = shape_taiwan(100); + fst_pt = [13, 0, 0]; + + rail = bezier_curve(0.05, [ + fst_pt, + fst_pt + [0, 0, 10], + fst_pt + [10, 0, 20], + fst_pt + [8, 0, 30], + fst_pt + [12, 0, 40], + fst_pt + [0, 0, 50], + fst_pt + [0, 0, 60] + ]); + + leng = len(rail); + twist = -90; + twist_step = twist / leng; + sections = rail_extruded_sections(taiwan, rail); + + rotated_sections = [ + for(i = [0:leng - 1]) + [ + for(p = sections[i]) + ptf_rotate(p, twist_step * i) + ] + ]; + + sweep(rotated_sections); + +![rail_extruded_sections](images/lib3x-rail_extruded_sections-3.JPG) + + use ; + use ; + use ; + use ; + use ; + + taiwan = shape_taiwan(100); + + /* + You can use any point as the first point of the edge path. + Just remember that your edge path radiates from the origin. + */ + fst_pt = [taiwan[0][0], taiwan[0][1], 0];//[13, 0, 0]; + a = atan2(fst_pt[1], fst_pt[0]); + rail = [ + fst_pt, + fst_pt + ptf_rotate([0, 0, 10], a), + fst_pt + ptf_rotate([10, 0, 20], a), + fst_pt + ptf_rotate([8, 0, 30], a), + fst_pt + ptf_rotate([10, 0, 40], a), + fst_pt + ptf_rotate([0, 0, 50], a), + fst_pt + ptf_rotate([0, 0, 60], a) + ]; + + #hull_polyline3d(rail); + sweep(rail_extruded_sections(taiwan, rail)); + +![rail_extruded_sections](images/lib3x-rail_extruded_sections-4.JPG) \ No newline at end of file diff --git a/examples/distorted_vase.scad b/examples/distorted_vase.scad index 99ec40a8..c1921f24 100644 --- a/examples/distorted_vase.scad +++ b/examples/distorted_vase.scad @@ -1,7 +1,7 @@ use ; use ; use ; -use ; +use ; use ; use ; use ; @@ -36,7 +36,7 @@ module distorted_vase(beginning_radius, thickness, fn, amplitude,curve_step, smo ]); - sections = path_scaling_sections(section, edge_path); + sections = rail_extruded_sections(section, edge_path); noise = perlin == 2 ? function(pts, seed) nz_perlin2s(pts, seed) : function(pts, seed) nz_perlin3s(pts, seed); diff --git a/examples/dragon/spiral_dragon.scad b/examples/dragon/spiral_dragon.scad index e81db68a..2bbf5682 100644 --- a/examples/dragon/spiral_dragon.scad +++ b/examples/dragon/spiral_dragon.scad @@ -5,7 +5,7 @@ use ; use ; use ; use ; -use ; +use ; use ; use ; use ; @@ -103,7 +103,7 @@ module flame_mountain(beginning_radius, fn, amplitude,curve_step, smoothness) { ]); - sections = path_scaling_sections(section, edge_path); + sections = rail_extruded_sections(section, edge_path); noise = function(pts, seed) nz_perlin2s(pts, seed); diff --git a/examples/superformula_vase.scad b/examples/superformula_vase.scad index e181b640..8402d55c 100644 --- a/examples/superformula_vase.scad +++ b/examples/superformula_vase.scad @@ -1,6 +1,6 @@ use ; use ; -use ; +use ; use ; use ; use ; @@ -27,7 +27,7 @@ module superformula_vase(phi_step, m, n, n3, d, r1, r2, h1, h2, t_step, twist) { function cal_sections(shapt_pts, edge_path, twist) = let( - sects = path_scaling_sections(shapt_pts, edge_path), + sects = rail_extruded_sections(shapt_pts, edge_path), leng = len(sects), twist_step = twist / leng ) @@ -50,7 +50,7 @@ module superformula_vase(phi_step, m, n, n3, d, r1, r2, h1, h2, t_step, twist) { [r2, 0, h2], ]); - offseted = bijection_offset(superformula, d); + offseted = bijection_offset(superformula, d, epsilon = 0.0000001); edge_path2 = [for(p = edge_path) p + [d, 0, 0]]; superformula2 = trim_shape(offseted, 3, len(offseted) - 1, epsilon = 0.0001); diff --git a/examples/taiwan/dancing_taiwan.scad b/examples/taiwan/dancing_taiwan.scad index 61320cfc..c6948d09 100644 --- a/examples/taiwan/dancing_taiwan.scad +++ b/examples/taiwan/dancing_taiwan.scad @@ -1,7 +1,7 @@ use ; use ; use ; -use ; +use ; use ; use ; use ; @@ -19,7 +19,7 @@ module dancing_formosan(x1, x2, x3, y1, y2, y3, twist, t_step) { function cal_sections(shapt_pts, edge_path, twist) = let( - sects = path_scaling_sections(shapt_pts, edge_path), + sects = rail_extruded_sections(shapt_pts, edge_path), leng = len(sects), twist_step = twist / leng ) diff --git a/src/rail_extruded_sections.scad b/src/rail_extruded_sections.scad new file mode 100644 index 00000000..493484aa --- /dev/null +++ b/src/rail_extruded_sections.scad @@ -0,0 +1,32 @@ +/** +* rail_extruded_sections.scad +* +* @copyright Justin Lin, 2019 +* @license https://opensource.org/licenses/lgpl-3.0.html +* +* @see https://openhome.cc/eGossip/OpenSCAD/lib3x-rail_extruded_sections.html +* +**/ + +use ; +use ; + +function rail_extruded_sections(shape_pts, rail) = + let( + start_point = rail[0], + base_leng = norm(start_point), + scaling_matrice = [ + for(p = rail) + let(s = norm([p[0], p[1], 0]) / base_leng) + m_scaling([s, s, 1]) + ], + leng_rail = len(rail) + ) + reverse([ + for(i = 0; i < leng_rail; i = i + 1) + [ + for(p = shape_pts) + let(scaled_p = scaling_matrice[i] * [p[0], p[1], rail[i][2], 1]) + [scaled_p[0], scaled_p[1], scaled_p[2]] + ] + ]); \ No newline at end of file