mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-08-05 06:17:32 +02:00
add rail_extruded_sections
This commit is contained in:
@@ -67,7 +67,7 @@ You can use any point as the first point of the edge path. Just remember that yo
|
|||||||
use <path_scaling_sections.scad>;
|
use <path_scaling_sections.scad>;
|
||||||
use <sweep.scad>;
|
use <sweep.scad>;
|
||||||
use <bezier_curve.scad>;
|
use <bezier_curve.scad>;
|
||||||
use <rotate_p.scad>;
|
use <ptf/ptf_rotate.scad>;
|
||||||
|
|
||||||
taiwan = shape_taiwan(100);
|
taiwan = shape_taiwan(100);
|
||||||
fst_pt = [13, 0, 0];
|
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(i = [0:leng - 1])
|
||||||
[
|
[
|
||||||
for(p = sections[i])
|
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 <shape_taiwan.scad>;
|
use <shape_taiwan.scad>;
|
||||||
use <path_scaling_sections.scad>;
|
use <path_scaling_sections.scad>;
|
||||||
use <sweep.scad>;
|
use <sweep.scad>;
|
||||||
use <rotate_p.scad>;
|
use <ptf/ptf_rotate.scad>;
|
||||||
|
|
||||||
taiwan = shape_taiwan(100);
|
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]);
|
a = atan2(fst_pt[1], fst_pt[0]);
|
||||||
edge_path = [
|
edge_path = [
|
||||||
fst_pt,
|
fst_pt,
|
||||||
fst_pt + rotate_p([0, 0, 10], a),
|
fst_pt + ptf_rotate([0, 0, 10], a),
|
||||||
fst_pt + rotate_p([10, 0, 20], a),
|
fst_pt + ptf_rotate([10, 0, 20], a),
|
||||||
fst_pt + rotate_p([8, 0, 30], a),
|
fst_pt + ptf_rotate([8, 0, 30], a),
|
||||||
fst_pt + rotate_p([10, 0, 40], a),
|
fst_pt + ptf_rotate([10, 0, 40], a),
|
||||||
fst_pt + rotate_p([0, 0, 50], a),
|
fst_pt + ptf_rotate([0, 0, 50], a),
|
||||||
fst_pt + rotate_p([0, 0, 60], a)
|
fst_pt + ptf_rotate([0, 0, 60], a)
|
||||||
];
|
];
|
||||||
|
|
||||||
#hull_polyline3d(edge_path);
|
#hull_polyline3d(edge_path);
|
||||||
|
127
docs/lib3x-rail_extruded_sections.md
Normal file
127
docs/lib3x-rail_extruded_sections.md
Normal file
@@ -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 <hull_polyline3d.scad>;
|
||||||
|
use <shape_taiwan.scad>;
|
||||||
|
use <rail_extruded_sections.scad>;
|
||||||
|
use <sweep.scad>;
|
||||||
|
|
||||||
|
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));
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
use <hull_polyline3d.scad>;
|
||||||
|
use <shape_taiwan.scad>;
|
||||||
|
use <rail_extruded_sections.scad>;
|
||||||
|
use <sweep.scad>;
|
||||||
|
use <bezier_curve.scad>;
|
||||||
|
|
||||||
|
|
||||||
|
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));
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
use <shape_taiwan.scad>;
|
||||||
|
use <rail_extruded_sections.scad>;
|
||||||
|
use <sweep.scad>;
|
||||||
|
use <bezier_curve.scad>;
|
||||||
|
use <ptf/ptf_rotate.scad>;
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
use <hull_polyline3d.scad>;
|
||||||
|
use <shape_taiwan.scad>;
|
||||||
|
use <rail_extruded_sections.scad>;
|
||||||
|
use <sweep.scad>;
|
||||||
|
use <ptf/ptf_rotate.scad>;
|
||||||
|
|
||||||
|
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));
|
||||||
|
|
||||||
|

|
@@ -1,7 +1,7 @@
|
|||||||
use <shape_circle.scad>;
|
use <shape_circle.scad>;
|
||||||
use <bezier_curve.scad>;
|
use <bezier_curve.scad>;
|
||||||
use <sweep.scad>;
|
use <sweep.scad>;
|
||||||
use <path_scaling_sections.scad>;
|
use <rail_extruded_sections.scad>;
|
||||||
use <bijection_offset.scad>;
|
use <bijection_offset.scad>;
|
||||||
use <util/rand.scad>;
|
use <util/rand.scad>;
|
||||||
use <noise/nz_perlin2s.scad>;
|
use <noise/nz_perlin2s.scad>;
|
||||||
@@ -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) :
|
noise = perlin == 2 ? function(pts, seed) nz_perlin2s(pts, seed) :
|
||||||
function(pts, seed) nz_perlin3s(pts, seed);
|
function(pts, seed) nz_perlin3s(pts, seed);
|
||||||
|
@@ -5,7 +5,7 @@ use <curve.scad>;
|
|||||||
use <sweep.scad>;
|
use <sweep.scad>;
|
||||||
use <shape_circle.scad>;
|
use <shape_circle.scad>;
|
||||||
use <bezier_curve.scad>;
|
use <bezier_curve.scad>;
|
||||||
use <path_scaling_sections.scad>;
|
use <rail_extruded_sections.scad>;
|
||||||
use <noise/nz_perlin2s.scad>;
|
use <noise/nz_perlin2s.scad>;
|
||||||
use <dragon_head.scad>;
|
use <dragon_head.scad>;
|
||||||
use <dragon_scales.scad>;
|
use <dragon_scales.scad>;
|
||||||
@@ -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);
|
noise = function(pts, seed) nz_perlin2s(pts, seed);
|
||||||
|
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
use <trim_shape.scad>;
|
use <trim_shape.scad>;
|
||||||
use <bezier_curve.scad>;
|
use <bezier_curve.scad>;
|
||||||
use <path_scaling_sections.scad>;
|
use <rail_extruded_sections.scad>;
|
||||||
use <sweep.scad>;
|
use <sweep.scad>;
|
||||||
use <ptf/ptf_rotate.scad>;
|
use <ptf/ptf_rotate.scad>;
|
||||||
use <bijection_offset.scad>;
|
use <bijection_offset.scad>;
|
||||||
@@ -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) =
|
function cal_sections(shapt_pts, edge_path, twist) =
|
||||||
let(
|
let(
|
||||||
sects = path_scaling_sections(shapt_pts, edge_path),
|
sects = rail_extruded_sections(shapt_pts, edge_path),
|
||||||
leng = len(sects),
|
leng = len(sects),
|
||||||
twist_step = twist / leng
|
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],
|
[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]];
|
edge_path2 = [for(p = edge_path) p + [d, 0, 0]];
|
||||||
superformula2 = trim_shape(offseted, 3, len(offseted) - 1, epsilon = 0.0001);
|
superformula2 = trim_shape(offseted, 3, len(offseted) - 1, epsilon = 0.0001);
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
use <trim_shape.scad>;
|
use <trim_shape.scad>;
|
||||||
use <bezier_curve.scad>;
|
use <bezier_curve.scad>;
|
||||||
use <shape_taiwan.scad>;
|
use <shape_taiwan.scad>;
|
||||||
use <path_scaling_sections.scad>;
|
use <rail_extruded_sections.scad>;
|
||||||
use <sweep.scad>;
|
use <sweep.scad>;
|
||||||
use <ptf/ptf_rotate.scad>;
|
use <ptf/ptf_rotate.scad>;
|
||||||
use <bijection_offset.scad>;
|
use <bijection_offset.scad>;
|
||||||
@@ -19,7 +19,7 @@ module dancing_formosan(x1, x2, x3, y1, y2, y3, twist, t_step) {
|
|||||||
|
|
||||||
function cal_sections(shapt_pts, edge_path, twist) =
|
function cal_sections(shapt_pts, edge_path, twist) =
|
||||||
let(
|
let(
|
||||||
sects = path_scaling_sections(shapt_pts, edge_path),
|
sects = rail_extruded_sections(shapt_pts, edge_path),
|
||||||
leng = len(sects),
|
leng = len(sects),
|
||||||
twist_step = twist / leng
|
twist_step = twist / leng
|
||||||
)
|
)
|
||||||
|
32
src/rail_extruded_sections.scad
Normal file
32
src/rail_extruded_sections.scad
Normal file
@@ -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 <util/reverse.scad>;
|
||||||
|
use <matrix/m_scaling.scad>;
|
||||||
|
|
||||||
|
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]]
|
||||||
|
]
|
||||||
|
]);
|
Reference in New Issue
Block a user