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

added line3d

This commit is contained in:
Justin Lin
2017-03-16 20:26:15 +08:00
parent b420a9bae3
commit c20c1ee830
6 changed files with 114 additions and 0 deletions

View File

@@ -8,6 +8,9 @@ These fundamental modules are helpful when playing OpenSCAD.
- [circular_sector](https://openhome.cc/eGossip/OpenSCAD/lib-circular_sector.html)
- [arc](https://openhome.cc/eGossip/OpenSCAD/lib-arc.html)
## 3D
- [line3d](https://openhome.cc/eGossip/OpenSCAD/lib-line3d.html)
## Transformations
- [hollow_out](https://openhome.cc/eGossip/OpenSCAD/lib-hollow_out.html)

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

42
docs/lib-line3d.md Normal file
View File

@@ -0,0 +1,42 @@
# line3d
Creates a 3D line from two points.
## Parameters
- `p1` : 3 element vector `[x, y, z]`.
- `p2` : 3 element vector `[x, y, z]`.
- `thickness` : The line thickness.
- `p1Style` : The end-cap style of the point `p1`. The value must be `CAP_BUTT`, `CAP_CIRCLE` or `CAP_SPHERE`. The default value is `CAP_CIRCLE`.
- `p2Style` : The end-cap style of the point `p2`. The value must be `CAP_BUTT`, `CAP_CIRCLE` or `CAP_ROUND`. The default value is `CAP_CIRCLE`.
- `fn` : It controlls the `$fn` value used by the `circle` or `sphere` module. The default value is `24`.
## Examples
line3d(
p1 = [0, 0, 0],
p2 = [10, 2, 10],
thickness = 1
);
![line3d](images/lib-line3d-1.JPG)
line3d(
p1 = [0, 0, 0],
p2 = [10, 2, 10],
thickness = 1,
p1Style = CAP_BUTT,
p2Style = CAP_BUTT
);
![line3d](images/lib-line3d-2.JPG)
line3d(
p1 = [0, 0, 0],
p2 = [10, 2, 10],
thickness = 1,
p1Style = CAP_SPHERE,
p2Style = CAP_SPHERE
);
![line3d](images/lib-line3d-3.JPG)

69
docs/line3d.scad Normal file
View File

@@ -0,0 +1,69 @@
/**
* line3d.scad
*
* Creates a 3D line from two points.
*
* @copyright Justin Lin, 2017
* @license https://opensource.org/licenses/lgpl-3.0.html
*
* @see https://openhome.cc/eGossip/OpenSCAD/lib-line3d.html
*
**/
CAP_BUTT = 0;
CAP_CIRCLE = 1;
CAP_SPHERE = 2;
module line3d(p1, p2, thickness, p1Style = CAP_CIRCLE, p2Style = CAP_CIRCLE, fn = 24) {
$fn = fn;
r = thickness / 2;
dx = p2[0] - p1[0];
dy = p2[1] - p1[1];
dz = p2[2] - p1[2];
length = sqrt(pow(dx, 2) + pow(dy, 2) + pow(dz, 2));
ay = 90 - atan2(dz, sqrt(pow(dx, 2) + pow(dy, 2)));
az = atan2(dy, dx);
module cap_butt() {
translate(p1)
rotate([0, ay, az])
linear_extrude(length)
circle(r);
}
module capCube(p) {
w = r / 1.414;
translate(p)
rotate([0, ay, az])
translate([0, 0, -w])
linear_extrude(w * 2)
circle(r);
}
module capSphere(p) {
translate(p)
rotate([0, ay, az])
sphere(r * 1.0087);
}
module cap(p, style) {
if(style == CAP_CIRCLE) {
capCube(p);
} else if(style == CAP_SPHERE) {
if(fn > 4) {
capSphere(p);
} else {
capCube(p);
}
}
}
cap_butt();
cap(p1, p1Style);
cap(p2, p2Style);
}