OpenSCAD prefers clockwise
BIN
docs/images/lib-polysections-10.JPG
Normal file
After Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 17 KiB |
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 24 KiB |
Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 19 KiB |
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 23 KiB |
Before Width: | Height: | Size: 25 KiB After Width: | Height: | Size: 22 KiB |
@@ -12,28 +12,30 @@ Looks like extruding along the path? Yes, it can perform the task; however, it's
|
|||||||
|
|
||||||
You can also view it as a better polyline3d module if you want. If you have only the points of a path, using `polyline3d` or `hull_polyline3d` is a simple solution. If you know the cross-sections along a path, you can use `polysections` to do more.
|
You can also view it as a better polyline3d module if you want. If you have only the points of a path, using `polyline3d` or `hull_polyline3d` is a simple solution. If you know the cross-sections along a path, you can use `polysections` to do more.
|
||||||
|
|
||||||
When using this module, you should use points to represent each cross-section.
|
When using this module, you should use points to represent each cross-section. The points of your 2D shape should have count-clockwise indexes. For example:
|
||||||
|
|
||||||
If your 2D shape is not solid, indexes of triangles are required. This module has a built-in index vector suitable for one type of hollow shapes. For example, if you have a cross-section such as:
|

|
||||||
|
|
||||||
|
If your 2D shape is hollow, set the `triangles` parameter to `"HOLLOW"` and index the points as the following:
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
When `triangles` is `"HOLLOW"`, the above shape will be cut into triangles such as:
|
You can cut triangles by yourself. For example, the above shape can be cut into triangles such as:
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
You can cut triangles by yourself, for example, the indexes of the above triangles is:
|
The indexes of the above triangles is:
|
||||||
|
|
||||||
[
|
[
|
||||||
[0, 3, 4],
|
[0, 4, 3],
|
||||||
[0, 4, 1],
|
[0, 1, 4],
|
||||||
[1, 4, 5],
|
[1, 5, 4],
|
||||||
[1, 5, 2],
|
[1, 2, 5],
|
||||||
[2, 5, 3],
|
[2, 3, 5],
|
||||||
[2, 3, 0]
|
[2, 0, 3]
|
||||||
]
|
]
|
||||||
|
|
||||||
Triangles may be defined in any order.
|
In this module, triangles may be defined in any order. Of course, [following the preference of OpenSCAD](https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Primitive_Solids#polyhedron) is ok.
|
||||||
|
|
||||||
## Parameters
|
## Parameters
|
||||||
|
|
||||||
@@ -44,24 +46,24 @@ Triangles may be defined in any order.
|
|||||||
|
|
||||||
include <rotate_p.scad>;
|
include <rotate_p.scad>;
|
||||||
include <polysections.scad>;
|
include <polysections.scad>;
|
||||||
|
|
||||||
section1 = [
|
section1 = [
|
||||||
[10, 0, 0],
|
[20, 0, 0],
|
||||||
[15, 10, 0],
|
[18, 9, 0],
|
||||||
[18, 9, 0],
|
[15, 10, 0],
|
||||||
[20, 0, 0]
|
[10, 0, 0]
|
||||||
];
|
];
|
||||||
|
|
||||||
// spin section1
|
// spin section1
|
||||||
sections = [
|
sections = [
|
||||||
for(i = [0:55])
|
for(i = [0:55])
|
||||||
[
|
[
|
||||||
for(p = section1)
|
for(p = section1)
|
||||||
let(pt = rotate_p(p, [90, 0, -10 * i]))
|
let(pt = rotate_p(p, [90, 0, 10 * i]))
|
||||||
[pt[0], pt[1] , pt[2] + i]
|
[pt[0], pt[1] , pt[2] + i]
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
|
||||||
polysections(sections);
|
polysections(sections);
|
||||||
|
|
||||||

|

|
||||||
@@ -71,15 +73,15 @@ Triangles may be defined in any order.
|
|||||||
|
|
||||||
section1 = [
|
section1 = [
|
||||||
// outer
|
// outer
|
||||||
[10, 0, 0],
|
[20, 0, 0],
|
||||||
[15, 10, 0],
|
[18, 9, 0],
|
||||||
[18, 9, 0],
|
[15, 10, 0],
|
||||||
[20, 0, 0],
|
[10, 0, 0],
|
||||||
// inner
|
// inner
|
||||||
[12, 2, 0],
|
[18, 2, 0],
|
||||||
[15, 7, 0],
|
[17, 7, 0],
|
||||||
[17, 7, 0],
|
[15, 7, 0],
|
||||||
[18, 2, 0]
|
[12, 2, 0]
|
||||||
];
|
];
|
||||||
|
|
||||||
// spin section1
|
// spin section1
|
||||||
@@ -87,7 +89,7 @@ Triangles may be defined in any order.
|
|||||||
for(i = [0:55])
|
for(i = [0:55])
|
||||||
[
|
[
|
||||||
for(p = section1)
|
for(p = section1)
|
||||||
let(pt = rotate_p(p, [90, 0, -10 * i]))
|
let(pt = rotate_p(p, [90, 0, 10 * i]))
|
||||||
[pt[0], pt[1] , pt[2] + i]
|
[pt[0], pt[1] , pt[2] + i]
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
@@ -101,13 +103,13 @@ Triangles may be defined in any order.
|
|||||||
|
|
||||||
section1 = [
|
section1 = [
|
||||||
// outer
|
// outer
|
||||||
[10, 0, 0],
|
[30, 0, 0],
|
||||||
[15, 10, 0],
|
[15, 10, 0],
|
||||||
[30, 0, 0],
|
[10, 0, 0],
|
||||||
// inner
|
// inner
|
||||||
[12, 1, 0],
|
[26, 1, 0],
|
||||||
[15, 8, 0],
|
[15, 8, 0],
|
||||||
[26, 1, 0],
|
[12, 1, 0],
|
||||||
];
|
];
|
||||||
|
|
||||||
// spin section1
|
// spin section1
|
||||||
@@ -115,7 +117,7 @@ Triangles may be defined in any order.
|
|||||||
for(i = [0:55])
|
for(i = [0:55])
|
||||||
[
|
[
|
||||||
for(p = section1)
|
for(p = section1)
|
||||||
let(pt = rotate_p(p, [90, 0, -10 * i]))
|
let(pt = rotate_p(p, [90, 0, 10 * i]))
|
||||||
[pt[0], pt[1] , pt[2] + i]
|
[pt[0], pt[1] , pt[2] + i]
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
@@ -123,13 +125,13 @@ Triangles may be defined in any order.
|
|||||||
polysections(
|
polysections(
|
||||||
sections = sections,
|
sections = sections,
|
||||||
triangles = [
|
triangles = [
|
||||||
[0, 3, 4],
|
[0, 3, 1],
|
||||||
[0, 4, 1],
|
[1, 3, 4],
|
||||||
[1, 4, 5],
|
[1, 4, 2],
|
||||||
[1, 5, 2],
|
[2, 4, 5],
|
||||||
[2, 5, 3],
|
[2, 5, 0],
|
||||||
[2, 3, 0]
|
[0, 5, 3]
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||

|

|
||||||
|
@@ -12,6 +12,13 @@
|
|||||||
**/
|
**/
|
||||||
|
|
||||||
module polysections(sections, triangles = "SOLID") {
|
module polysections(sections, triangles = "SOLID") {
|
||||||
|
function reverse(vt) =
|
||||||
|
let(leng = len(vt))
|
||||||
|
[
|
||||||
|
for(i = [0:leng - 1])
|
||||||
|
vt[leng - 1 - i]
|
||||||
|
];
|
||||||
|
|
||||||
function side_indexes(sects, begin_idx = 0) =
|
function side_indexes(sects, begin_idx = 0) =
|
||||||
let(
|
let(
|
||||||
leng_sects = len(sects),
|
leng_sects = len(sects),
|
||||||
@@ -39,13 +46,14 @@ module polysections(sections, triangles = "SOLID") {
|
|||||||
);
|
);
|
||||||
|
|
||||||
module solid_sections(sects) {
|
module solid_sections(sects) {
|
||||||
|
leng_sects = len(sects);
|
||||||
leng_pts_sect = len(sects[0]);
|
leng_pts_sect = len(sects[0]);
|
||||||
|
|
||||||
first_idxes = [for(i = [0:leng_pts_sect - 1]) leng_pts_sect - 1 - i];
|
first_idxes = [for(i = [0:leng_pts_sect - 1]) leng_pts_sect - 1 - i];
|
||||||
|
|
||||||
last_idxes = [
|
last_idxes = [
|
||||||
for(i = [0:leng_pts_sect - 1])
|
for(i = [0:leng_pts_sect - 1])
|
||||||
i + leng_pts_sect * (len(sects) - 1)
|
i + leng_pts_sect * (leng_sects - 1)
|
||||||
];
|
];
|
||||||
|
|
||||||
v_pts = [
|
v_pts = [
|
||||||
@@ -75,17 +83,28 @@ module polysections(sections, triangles = "SOLID") {
|
|||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
|
||||||
function end_idxes(begin_idx) =
|
function first_idxes() =
|
||||||
[
|
[
|
||||||
for(i = [0:half_leng_sect - 1])
|
for(i = [0:half_leng_sect - 1])
|
||||||
[
|
[
|
||||||
begin_idx + i,
|
i,
|
||||||
begin_idx + (i + 1) % half_leng_sect,
|
i + half_leng_v_pts,
|
||||||
begin_idx + (i + 1) % half_leng_sect + half_leng_v_pts,
|
(i + 1) % half_leng_sect + half_leng_v_pts,
|
||||||
begin_idx + i + half_leng_v_pts
|
(i + 1) % half_leng_sect
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
|
||||||
|
function last_idxes(begin_idx) =
|
||||||
|
[
|
||||||
|
for(i = [0:half_leng_sect - 1])
|
||||||
|
[
|
||||||
|
begin_idx + i,
|
||||||
|
begin_idx + (i + 1) % half_leng_sect,
|
||||||
|
begin_idx + (i + 1) % half_leng_sect + half_leng_v_pts,
|
||||||
|
begin_idx + i + half_leng_v_pts
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
outer_sects = strip_sects(0, half_leng_sect - 1);
|
outer_sects = strip_sects(0, half_leng_sect - 1);
|
||||||
inner_sects = strip_sects(half_leng_sect, leng_sect - 1);
|
inner_sects = strip_sects(half_leng_sect, leng_sect - 1);
|
||||||
|
|
||||||
@@ -100,10 +119,14 @@ module polysections(sections, triangles = "SOLID") {
|
|||||||
inner_v_pts = to_v_pts(inner_sects);
|
inner_v_pts = to_v_pts(inner_sects);
|
||||||
|
|
||||||
outer_idxes = side_indexes(outer_sects);
|
outer_idxes = side_indexes(outer_sects);
|
||||||
inner_idxes = side_indexes(inner_sects, half_leng_v_pts);
|
inner_idxes = [
|
||||||
first_idxes = end_idxes(0);
|
for(idxes = side_indexes(inner_sects, half_leng_v_pts))
|
||||||
last_idxes = end_idxes(half_leng_v_pts - half_leng_sect);
|
reverse(idxes)
|
||||||
|
];
|
||||||
|
|
||||||
|
first_idxes = first_idxes();
|
||||||
|
last_idxes = last_idxes(half_leng_v_pts - half_leng_sect);
|
||||||
|
|
||||||
polyhedron(
|
polyhedron(
|
||||||
concat(outer_v_pts, inner_v_pts),
|
concat(outer_v_pts, inner_v_pts),
|
||||||
concat(first_idxes, outer_idxes, inner_idxes, last_idxes)
|
concat(first_idxes, outer_idxes, inner_idxes, last_idxes)
|
||||||
@@ -116,8 +139,8 @@ module polysections(sections, triangles = "SOLID") {
|
|||||||
points = concat(tri1, tri2),
|
points = concat(tri1, tri2),
|
||||||
faces = [
|
faces = [
|
||||||
[0, 1, 2],
|
[0, 1, 2],
|
||||||
[3, 4, 5],
|
[3, 5, 4],
|
||||||
[0, 1, 4], [1, 2, 5], [2, 0, 3],
|
[0, 4, 1], [1, 5, 2], [2, 3, 0],
|
||||||
[0, 3, 4], [1, 4, 5], [2, 5, 3]
|
[0, 3, 4], [1, 4, 5], [2, 5, 3]
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|