diff --git a/README.md b/README.md index af8cebb1..c43477a8 100644 --- a/README.md +++ b/README.md @@ -364,8 +364,8 @@ These examples incubate dotSCAD and dotSCAD refactors these examples. See [examp [**surface/sf_curve**(levels, curve_path, ...)](https://openhome.cc/eGossip/OpenSCAD/lib3x-sf_curve.html) | curve a photo. [**surface/sf_splines**(ctrl_pts, row_spline, column_spline)](https://openhome.cc/eGossip/OpenSCAD/lib3x-sf_splines.html) | generalized-spline surface. [**surface/sf_thicken**(points, thickness, ...)](https://openhome.cc/eGossip/OpenSCAD/lib3x-sf_thicken.html) | thicken a surface. -**surface/sf_solidifyT**(points1, points2, triangles) | solidify two triangulated surfaces. -**surface/sf_thickenT**(points, thickness, ...) | thicken a triangulated surface. +[**surface/sf_solidifyT**(points1, points2, triangles)](https://openhome.cc/eGossip/OpenSCAD/lib3x-sf_solidifyT.html) | solidify two surfaces with triangular mesh. +[**surface/sf_thickenT**(points, thickness, ...)](https://openhome.cc/eGossip/OpenSCAD/lib3x-sf_thickenT.html) | thicken a surface with triangular mesh. ## Triangle diff --git a/docs/images/lib3x-sf_solidifyT-1.JPG b/docs/images/lib3x-sf_solidifyT-1.JPG new file mode 100644 index 00000000..b0dc4e74 Binary files /dev/null and b/docs/images/lib3x-sf_solidifyT-1.JPG differ diff --git a/docs/images/lib3x-sf_solidifyT-2.JPG b/docs/images/lib3x-sf_solidifyT-2.JPG new file mode 100644 index 00000000..24749404 Binary files /dev/null and b/docs/images/lib3x-sf_solidifyT-2.JPG differ diff --git a/docs/images/lib3x-sf_thickenT-1.JPG b/docs/images/lib3x-sf_thickenT-1.JPG new file mode 100644 index 00000000..cdf42ccd Binary files /dev/null and b/docs/images/lib3x-sf_thickenT-1.JPG differ diff --git a/docs/images/lib3x-sf_thickenT-2.JPG b/docs/images/lib3x-sf_thickenT-2.JPG new file mode 100644 index 00000000..7a8a223d Binary files /dev/null and b/docs/images/lib3x-sf_thickenT-2.JPG differ diff --git a/docs/lib3x-sf_solidifyT.md b/docs/lib3x-sf_solidifyT.md new file mode 100644 index 00000000..58e0f671 --- /dev/null +++ b/docs/lib3x-sf_solidifyT.md @@ -0,0 +1,55 @@ +# sf_solidifyT + +It solidifies two surfaces with triangular mesh. + +**Since:** 3.1 + +## Parameters + +- `points1` : A list of `[x, y, z]`s. +- `points2` : A list of `[x, y, z]`s. +- `triangles` : Determine which points are connected by an edge. All triangles have points in the same direction, counter-clockwise. See examples below. + +## Examples + + use ; + use ; + + points = [for(i = [0:50]) rands(-300, 300, 2)]; + triangles = tri_delaunay(points); + + pts = [for(p = points) [p[0], p[1], rands(100, 150, 1)[0]]]; + pts2 = [for(p = pts) [p[0], p[1], p[2] - 100]]; + + sf_solidifyT(pts, pts2, triangles = triangles); + +![sf_solidifyT](images/lib3x-sf_solidifyT-1.JPG) + + use ; + use ; + + thickness = .2; + a_step = 10; + r_step = 0.2; + scale = 100; + + function f(x, y) = (pow(y,2)/pow(2, 2))-(pow(x,2)/pow(2, 2)); + + pts2d = [ + for(a = [a_step:a_step:360]) + for(r = [r_step:r_step:2]) + let( + x = round(r * cos(a) * 100) / 100, + y = round(r * sin(a) * 100) / 100 + ) + [x, y] + ]; + + points1 = [for(p = pts2d) scale * [p[0], p[1], f(p[0], p[1])]]; + points2 = [for(p = points1) [p[0], p[1], p[2] - scale * thickness]]; + triangles = tri_delaunay(pts2d); + + + sf_solidifyT(points1, points2, triangles); + +![sf_solidifyT](images/lib3x-sf_solidifyT-2.JPG) \ No newline at end of file diff --git a/docs/lib3x-sf_thickenT.md b/docs/lib3x-sf_thickenT.md new file mode 100644 index 00000000..926b7a80 --- /dev/null +++ b/docs/lib3x-sf_thickenT.md @@ -0,0 +1,65 @@ +# sf_thickenT + +It thickens a surface with triangular mesh. + +## Parameters + +- `points` : A list of `[x, y, z]`s. +- `thickness` : The depth of the thickening. +- `triangles` : Determine which points are connected by an edge. All triangles have points in the same direction, counter-clockwise. If it's ignored, `sf_thickenT` would use `[x, y]` to do Delaunay trianglation. +- `direction` : The direction of thickening. It accepts `"BOTH"` (default), `"FORWARD"` or `"BACKWARD"`. Thickening is applied in both directions from the surface, the direction of the surface normals or the opposite direction to the surface normals. It also accept a direction vector `[x, y, z]`. Thickening is only applied in the direction you give. + +## Examples + + use ; + + radius = 100; + width = 2; + thickness = .2; + + a_step = 10; + r_step = 0.2; + + function f(x, y) = (pow(y,2)/pow(2, 2))-(pow(x,2)/pow(2, 2)); + + points = [ + for(a = [a_step:a_step:360]) + for(r = [r_step:r_step:2]) + let( + x = round(r * cos(a) * 100) / 100, + y = round(r * sin(a) * 100) / 100 + ) + [x, y, f(x, y)] + ]; + + sf_thickenT(points, thickness); + +![sf_thickenT](images/lib3x-sf_thickenT-1.JPG) + + use ; + use ; + + u_step = 10; + r_step = 0.2; + thickness = .2; + + points = [ + for(u = [0:u_step:360]) + for(v = [-1:r_step:1]) + let( + x = (1 + v / 2 * cos(u / 2)) * cos(u), + y = (1 + v / 2 * cos(u / 2)) * sin(u), + z = v / 2 * sin(u / 2) + ) + [x, y, z] + ]; + + triangles = tri_delaunay([ + for(u = [0:u_step:360]) + for(v = [-1:r_step:1]) + [v, u] + ]); + + sf_thickenT(points, thickness, triangles); + +![sf_thickenT](images/lib3x-sf_thickenT-2.JPG) \ No newline at end of file diff --git a/src/surface/sf_solidifyT.scad b/src/surface/sf_solidifyT.scad index c4f8959f..81946b66 100644 --- a/src/surface/sf_solidifyT.scad +++ b/src/surface/sf_solidifyT.scad @@ -1,3 +1,13 @@ +/** +* sf_solidifyT.scad +* +* @copyright Justin Lin, 2021 +* @license https://opensource.org/licenses/lgpl-3.0.html +* +* @see https://openhome.cc/eGossip/OpenSCAD/lib3x-sf_solidifyT.html +* +**/ + use <../util/set/hashset.scad>; use <../util/set/hashset_has.scad>; use <../util/set/hashset_add.scad>; @@ -52,31 +62,4 @@ module sf_solidifyT(points1, points2, triangles) { side_faces ) ); -} - -/* -use ; -use ; -use ; - -use ; - -points = [for(i = [0:50]) rands(-200, 200, 2)]; - -delaunay = tri_delaunay(points, ret = "DELAUNAY"); - -// count-clockwise -indices = tri_delaunay_indices(delaunay); -shapes = tri_delaunay_shapes(delaunay); - -for(t = shapes) { - offset(-1) - polygon(t); -} - -pts = [for(p = points) [p[0], p[1], rands(100, 150, 1)[0]]]; -pts2 = [for(p = pts) [p[0], p[1], p[2] - 10]]; - -sf_solidifyT(pts, pts2, triangles = indices); - -*/ \ No newline at end of file +} \ No newline at end of file diff --git a/src/surface/sf_thickenT.scad b/src/surface/sf_thickenT.scad index 9872fe6c..cbc55d70 100644 --- a/src/surface/sf_thickenT.scad +++ b/src/surface/sf_thickenT.scad @@ -1,3 +1,13 @@ +/** +* sf_thickenT.scad +* +* @copyright Justin Lin, 2021 +* @license https://opensource.org/licenses/lgpl-3.0.html +* +* @see https://openhome.cc/eGossip/OpenSCAD/lib3x-sf_thickenT.html +* +**/ + use <../util/sort.scad>; use <../util/find_index.scad>; use <../util/slice.scad>; @@ -95,70 +105,4 @@ module sf_thickenT(points, thickness, triangles = undef, direction = "BOTH") { sf_solidifyT(pts1, pts2, real_triangles); } } -} - -/* - -use ; -use ; -use ; - -use ; - -points = [for(i = [0:50]) rands(-200, 200, 2)]; - -delaunay = tri_delaunay(points, ret = "DELAUNAY"); - -indices = tri_delaunay_indices(delaunay); -shapes = tri_delaunay_shapes(delaunay); - -for(tri = shapes) { - offset(-1) - polygon(tri); -} - -pts = [for(p = points) [p[0], p[1], rands(100, 120, 1)[0]]]; -thickness = 5; - -sf_thickenT(pts, thickness, indices); - -*/ - -/* -use ; -use ; -use ; - -use ; - -points = [for(i = [0:50]) rands(-200, 200, 3)]; -pts = [for(p = points) [p[0], p[1], rands(100, 120, 1)[0]]]; -thickness = 5; - -sf_thickenT(pts, thickness); -*/ - -/* -use ; - -radius = 100; -width = 2; -thickness = .2; - -a_step = 10; -r_step = 0.2; - -function f(x, y) = (pow(y,2)/pow(2, 2))-(pow(x,2)/pow(2, 2)); - -points = [ - for(a = [a_step:a_step:360]) - for(r = [r_step:r_step:2]) - let( - x = round(r * cos(a) * 100) / 100, - y = round(r * sin(a) * 100) / 100 - ) - [x, y, f(x, y)] -]; - -sf_thickenT(points, thickness, direction = [0, 0, 1]); -*/ \ No newline at end of file +} \ No newline at end of file