1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-01-17 14:18:13 +01:00
This commit is contained in:
Justin Lin 2020-12-13 10:53:24 +08:00
parent 0e70941db2
commit 9ccadf733c
6 changed files with 55 additions and 27 deletions

View File

@ -235,7 +235,7 @@ These examples incubate dotSCAD and dotSCAD refactors these examples. See [examp
### Path
- curve
- [curve](https://openhome.cc/eGossip/OpenSCAD/lib2x-curve.html)
- bauer_spiral
- fibonacci_lattice

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB

43
docs/lib2x-curve.md Normal file
View File

@ -0,0 +1,43 @@
# curve
Draws a curved line from control points. The curve is drawn only from the 2nd control point to the second-last control point. It's an implementation of [Centripetal Catmull-Rom spline](https://en.wikipedia.org/wiki/Centripetal_Catmull%E2%80%93Rom_spline).
**Since:** 2.5
## Parameters
- `t_step` : The distance between two points of the generated curve.
- `points` : A list of `[x, y]` or `[x, y, z]` control points.
- `tightness` : You can view it as the curve tigntness if you provide a value between 0.0 and 1.0. The default value is 0.0. The value 1.0 connects all the points with straight lines. The value greater than 1.0 or less than 0.0 is also acceptable because it defines how to generate a bezier curve every four control points.
![curve](images/lib2x-curve-1.JPG)
![curve](images/lib2x-curve-2.JPG)
## Examples
use <curve.scad>;
use <hull_polyline3d.scad>;
pts = [
[28, 2, 1],
[15, 8, -10],
[2, 14, 5],
[28, 14, 2],
[15, 21, 9],
[2, 28, 0]
];
t_step = 0.05;
tightness = 0;
points = curve(t_step, pts, tightness);
hull_polyline3d(points, 1);
#for(pt = pts) {
translate(pt)
sphere(1);
}
#hull_polyline3d(pts, .1);
![curve](images/lib2x-curve-3.JPG)

View File

@ -1,3 +1,13 @@
/**
* crystal_ball.scad
*
* @copyright Justin Lin, 2020
* @license https://opensource.org/licenses/lgpl-3.0.html
*
* @see https://openhome.cc/eGossip/OpenSCAD/lib2x-curve.html
*
**/
use <_impl/_catmull_rom_spline.scad>;
function curve(t_step, points, tightness = 0) =
@ -11,29 +21,4 @@ function curve(t_step, points, tightness = 0) =
for(i = [0:len(pts) - 2]) pts[i]
],
[points[leng - 2]]
);
/*
use <curve.scad>;
use <hull_polyline3d.scad>;
pts = [
[280, 20, 10],
[150, 80, -100],
[20, 140, 50],
[280, 140, 20],
[150, 210, 90],
[20, 280, 0]
];
#for(pt = pts) {
translate(pt)
sphere(10);
}
t_step = 0.1;
tightness = 0;
points = curve(t_step, pts, tightness);
hull_polyline3d(points, 5);
*/
);