mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-08-20 05:21:38 +02:00
added polyline3d
This commit is contained in:
@@ -16,6 +16,7 @@ I've been using OpenSCAD for years and created some funny things. Some of them i
|
|||||||
|
|
||||||
- 3D
|
- 3D
|
||||||
- [line3d](https://openhome.cc/eGossip/OpenSCAD/lib-line3d.html)
|
- [line3d](https://openhome.cc/eGossip/OpenSCAD/lib-line3d.html)
|
||||||
|
- [polyline3d](https://openhome.cc/eGossip/OpenSCAD/lib-polyline3d.html)
|
||||||
|
|
||||||
- Transformations
|
- Transformations
|
||||||
- [hollow_out](https://openhome.cc/eGossip/OpenSCAD/lib-hollow_out.html)
|
- [hollow_out](https://openhome.cc/eGossip/OpenSCAD/lib-hollow_out.html)
|
||||||
|
BIN
docs/images/lib-polyline3d-1.JPG
Normal file
BIN
docs/images/lib-polyline3d-1.JPG
Normal file
Binary file not shown.
After Width: | Height: | Size: 41 KiB |
BIN
docs/images/lib-polyline3d-2.JPG
Normal file
BIN
docs/images/lib-polyline3d-2.JPG
Normal file
Binary file not shown.
After Width: | Height: | Size: 40 KiB |
BIN
docs/images/lib-polyline3d-3.JPG
Normal file
BIN
docs/images/lib-polyline3d-3.JPG
Normal file
Binary file not shown.
After Width: | Height: | Size: 38 KiB |
BIN
docs/images/lib-polyline3d-4.JPG
Normal file
BIN
docs/images/lib-polyline3d-4.JPG
Normal file
Binary file not shown.
After Width: | Height: | Size: 66 KiB |
65
docs/lib-polyline3d.md
Normal file
65
docs/lib-polyline3d.md
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
# polyline3d
|
||||||
|
|
||||||
|
Creates a polyline from a list of `[x, y, z]` coordinates. It depends on the `line3d` module so you have to `include` line3d.scad.
|
||||||
|
|
||||||
|
## Parameters
|
||||||
|
|
||||||
|
- `points` : The list of `[x, y, z]` points of the polyline. : A vector of 3 element vectors. The points are indexed from 0 to n-1.
|
||||||
|
- `thickness` : The line thickness.
|
||||||
|
- `startingStyle` : The end-cap style of the starting point. The value must be `CAP_BUTT`, `CAP_CIRCLE` or `CAP_SPHERE` (defined in line3d.scad). The default value is `CAP_CIRCLE`.
|
||||||
|
- endingStyle : The end-cap style of the ending point. The value must be `CAP_BUTT`, `CAP_CIRCLE` or `CAP_SPHERE` (defined in line3d.scad). The default value is `CAP_CIRCLE`.
|
||||||
|
- `fn` : It controlls the `$fn` value used by the `circle` and `sphere` module. The default value is `24`.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
polyline3d(
|
||||||
|
points = [
|
||||||
|
[1, 2, 1],
|
||||||
|
[-5, -4, 2],
|
||||||
|
[-5, 3, 3],
|
||||||
|
[5, 5, 4]
|
||||||
|
],
|
||||||
|
thickness = 1
|
||||||
|
);
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
polyline3d(
|
||||||
|
points = [
|
||||||
|
[1, 2, 1],
|
||||||
|
[-5, -4, 2],
|
||||||
|
[-5, 3, 3],
|
||||||
|
[5, 5, 4]
|
||||||
|
],
|
||||||
|
thickness = 1,
|
||||||
|
endingStyle = CAP_SPHERE
|
||||||
|
);
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
polyline3d(
|
||||||
|
points = [
|
||||||
|
[1, 2, 1],
|
||||||
|
[-5, -4, 2],
|
||||||
|
[-5, 3, 3],
|
||||||
|
[5, 5, 4]
|
||||||
|
],
|
||||||
|
thickness = 1,
|
||||||
|
startingStyle = CAP_SPHERE,
|
||||||
|
endingStyle = CAP_SPHERE
|
||||||
|
);
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
r = 20;
|
||||||
|
h = 5;
|
||||||
|
fa = 15;
|
||||||
|
circles = 10;
|
||||||
|
|
||||||
|
points = [
|
||||||
|
for(a = [0:fa:360 * circles])
|
||||||
|
[r * cos(a), r * sin(a), h / (360 / fa) * (a / fa)]
|
||||||
|
];
|
||||||
|
polyline3d(points, thickness = 1);
|
||||||
|
|
||||||
|

|
35
src/polyline3d.scad
Normal file
35
src/polyline3d.scad
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
/**
|
||||||
|
* polyline3d.scad
|
||||||
|
*
|
||||||
|
* Creates a 3D polyline from a list of `[x, y, z]` coordinates.
|
||||||
|
* It depends on the line3d module so you have to include line3d.scad.
|
||||||
|
*
|
||||||
|
* @copyright Justin Lin, 2017
|
||||||
|
* @license https://opensource.org/licenses/lgpl-3.0.html
|
||||||
|
*
|
||||||
|
* @see https://openhome.cc/eGossip/OpenSCAD/lib-polyline3d.html
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
|
||||||
|
module polyline3d(points, thickness, startingStyle = CAP_CIRCLE, endingStyle = CAP_CIRCLE, fn = 24) {
|
||||||
|
module line_segment(index) {
|
||||||
|
styles = index == 1 ? [startingStyle, CAP_BUTT] : (
|
||||||
|
index == len(points) - 1 ? [CAP_SPHERE, endingStyle] : [
|
||||||
|
CAP_SPHERE, CAP_BUTT
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
line3d(points[index - 1], points[index], thickness,
|
||||||
|
p1Style = styles[0], p2Style = styles[1],
|
||||||
|
fn = fn);
|
||||||
|
}
|
||||||
|
|
||||||
|
module polyline3d_inner(points, index) {
|
||||||
|
if(index < len(points)) {
|
||||||
|
line_segment(index);
|
||||||
|
polyline3d_inner(points, index + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
polyline3d_inner(points, 1);
|
||||||
|
}
|
Reference in New Issue
Block a user