1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-01-17 14:18:13 +01:00
dotSCAD/docs/lib3x-bspline_curve.md

89 lines
1.9 KiB
Markdown
Raw Normal View History

2019-08-07 21:07:31 +08:00
# bspline_curve
2021-11-18 08:08:50 +08:00
[B-spline](https://en.wikipedia.org/wiki/B-spline) interpolation using [de Boor's algorithm](https://en.wikipedia.org/wiki/De_Boor%27s_algorithm). This function returns points of the B-spline path.
2019-08-07 21:07:31 +08:00
2019-08-24 10:13:25 +08:00
**Since:** 2.1
2019-08-07 21:07:31 +08:00
## Parameters
- `t_step` : The increment amount along the curve in the [0, 1] range.
- `degree` : The degree of B-spline. Must be less than or equal to `len(points) - 1`.
- `points` : A list of `[x, y]` or `[x, y, z]` control points.
- `knots` : The knot vector. It's a non-decreasing sequence with length `len(points) + degree + 1`. If not provided, a uniform knot vector is generated automatically.
- `weights` : The weights of control points. If not provided, the weight of each point is 1.
## Examples
2022-06-06 13:11:46 +08:00
use <bspline_curve.scad>
2019-08-07 21:07:31 +08:00
points = [
[-10, 0],
[-5, 5],
[ 5, -5],
[ 10, 0]
];
color("red") for(p = points) {
translate(p)
sphere(0.5);
}
// knots: [0, 1, 2, 3, 4, 5, 6]
// weights: [1, 1, 1, 1]
for(p = bspline_curve(0.01, 2, points)) {
translate(p)
sphere(0.1);
}
2021-02-24 21:09:54 +08:00
![bspline_curve](images/lib3x-bspline_curve-1.JPG)
2019-08-07 21:07:31 +08:00
2022-06-06 13:11:46 +08:00
use <bspline_curve.scad>
2019-08-07 21:07:31 +08:00
points = [
[-10, 0],
[-5, 5],
[ 5, -5],
[ 10, 0]
];
// a non-uniform B-spline curve
knots = [0, 1/8, 1/4, 1/2, 3/4, 4/5, 1];
2022-04-06 17:44:11 +08:00
color("red")
for(p = points) {
2019-08-07 21:07:31 +08:00
translate(p)
sphere(0.5);
}
for(p = bspline_curve(0.01, 2, points, knots)) {
translate(p)
sphere(0.1);
}
2021-02-24 21:09:54 +08:00
![bspline_curve](images/lib3x-bspline_curve-2.JPG)
2019-08-07 21:07:31 +08:00
2022-06-06 13:11:46 +08:00
use <bspline_curve.scad>
2019-08-07 21:07:31 +08:00
points = [
[-10, 0],
[-5, 5],
[ 5, -5],
[ 10, 0]
];
2019-10-11 20:47:21 +08:00
// For a clamped B-spline curve, the first `degree + 1` and the last `degree + 1` knots must be identical.
2019-08-07 21:07:31 +08:00
knots = [0, 0, 0, 1, 2, 2, 2];
2022-04-06 17:44:11 +08:00
color("red")
for(p = points) {
2019-08-07 21:07:31 +08:00
translate(p)
sphere(0.5);
}
for(p = bspline_curve(0.01, 2, points, knots)) {
translate(p)
sphere(0.1);
}
2021-02-24 21:09:54 +08:00
![bspline_curve](images/lib3x-bspline_curve-3.JPG)