1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-08-06 06:47:46 +02:00

triangles : counter-clockwise

This commit is contained in:
Justin Lin
2021-06-26 20:39:36 +08:00
parent bed2cf49fa
commit 74ed27cbc4

View File

@@ -5,10 +5,12 @@ use <../util/set/hashset_del.scad>;
use <../util/set/hashset_elems.scad>; use <../util/set/hashset_elems.scad>;
module sf_solidify_tri(points1, points2, triangles) { module sf_solidify_tri(points1, points2, triangles) {
// triangles : clockwise // triangles : counter-clockwise
leng = len(points1); leng = len(points1);
assert(leng == len(points2), "The length of points1 must equal to the length of points2"); assert(leng == len(points2), "The length of points1 must equal to the length of points2");
tris = [for(tri = triangles) [tri[2], tri[1], tri[0]]];
function de_pairs(tri_edges) = function de_pairs(tri_edges) =
let( let(
leng = len(tri_edges), leng = len(tri_edges),
@@ -24,7 +26,7 @@ module sf_solidify_tri(points1, points2, triangles) {
_de_pairs(tri_edges, leng, hashset_add(edges, edge), i + 1); _de_pairs(tri_edges, leng, hashset_add(edges, edge), i + 1);
tri_edges = [ tri_edges = [
for(tri = triangles) for(tri = tris)
each [ each [
[tri[0], tri[1]], [tri[0], tri[1]],
[tri[1], tri[2]], [tri[1], tri[2]],
@@ -43,8 +45,8 @@ module sf_solidify_tri(points1, points2, triangles) {
polyhedron( polyhedron(
points = concat(points1, points2), points = concat(points1, points2),
faces = concat( faces = concat(
triangles, tris,
[for(tri = triangles) [tri[2], tri[1], tri[0]] + [leng, leng, leng]], [for(tri = triangles) tri + [leng, leng, leng]],
side_faces side_faces
) )
); );
@@ -61,11 +63,10 @@ points = [for(i = [0:50]) rands(-200, 200, 2)];
delaunay = tri_delaunay(points, ret = "DELAUNAY"); delaunay = tri_delaunay(points, ret = "DELAUNAY");
// count-clockwise (dotSCAD 2D polygon convention) // count-clockwise
indices = tri_delaunay_indices(delaunay); indices = tri_delaunay_indices(delaunay);
shapes = tri_delaunay_shapes(delaunay); shapes = tri_delaunay_shapes(delaunay);
for(t = shapes) { for(t = shapes) {
offset(-1) offset(-1)
polygon(t); polygon(t);
@@ -74,8 +75,6 @@ for(t = shapes) {
pts = [for(p = points) [p[0], p[1], rands(100, 150, 1)[0]]]; pts = [for(p = points) [p[0], p[1], rands(100, 150, 1)[0]]];
pts2 = [for(p = pts) [p[0], p[1], p[2] - 10]]; pts2 = [for(p = pts) [p[0], p[1], p[2] - 10]];
// triangles: clockwise (openscad 3D face convention) sf_solidify_tri(pts, pts2, triangles = indices);
sf_solidify_tri(pts, pts2,
triangles = [for(tri = indices) [tri[2], tri[1], tri[0]]]);
*/ */