Merge branch 'v1.1.0'
# Conflicts: # src/along_with.scad # src/path_extrude.scad # src/rotate_p.scad
12
README.md
@ -1,4 +1,4 @@
|
||||
# dotSCAD
|
||||
# dotSCAD 1.1
|
||||
|
||||
> Helpful modules and functions when playing OpenSCAD.
|
||||
|
||||
@ -54,6 +54,7 @@ Too many dependencies? Because OpenSCAD doesn't provide namespace management, I
|
||||
- [along_with](https://openhome.cc/eGossip/OpenSCAD/lib-along_with.html)
|
||||
- [hollow_out](https://openhome.cc/eGossip/OpenSCAD/lib-hollow_out.html)
|
||||
- [bend](https://openhome.cc/eGossip/OpenSCAD/lib-bend.html)
|
||||
- [shear](https://openhome.cc/eGossip/OpenSCAD/lib-shear.html)
|
||||
|
||||
- Functon
|
||||
- [rotate_p](https://openhome.cc/eGossip/OpenSCAD/lib-rotate_p.html)
|
||||
@ -102,6 +103,15 @@ Too many dependencies? Because OpenSCAD doesn't provide namespace management, I
|
||||
- [archimedean_spiral_extrude](https://openhome.cc/eGossip/OpenSCAD/lib-archimedean_spiral_extrude.html)
|
||||
- [sphere_spiral_extrude](https://openhome.cc/eGossip/OpenSCAD/lib-sphere_spiral_extrude.html)
|
||||
|
||||
- Matrix
|
||||
- [m_multiply](https://openhome.cc/eGossip/OpenSCAD/lib-m_multiply.html)
|
||||
- [m_cumulate](https://openhome.cc/eGossip/OpenSCAD/lib-m_cumulate.html)
|
||||
- [m_translation](https://openhome.cc/eGossip/OpenSCAD/lib-m_translation.html)
|
||||
- [m_rotation](https://openhome.cc/eGossip/OpenSCAD/lib-m_rotation.html)
|
||||
- [m_scaling](https://openhome.cc/eGossip/OpenSCAD/lib-m_scaling.html)
|
||||
- [m_mirror](https://openhome.cc/eGossip/OpenSCAD/lib-m_mirror.html)
|
||||
- [m_shearing](https://openhome.cc/eGossip/OpenSCAD/lib-m_shearing.html)
|
||||
|
||||
- Other
|
||||
- [turtle2d](https://openhome.cc/eGossip/OpenSCAD/lib-turtle2d.html)
|
||||
- [turtle3d](https://openhome.cc/eGossip/OpenSCAD/lib-turtle3d.html)
|
||||
|
BIN
docs/images/lib-m_cumulate-1.JPG
Normal file
After Width: | Height: | Size: 34 KiB |
BIN
docs/images/lib-m_mirror-1.JPG
Normal file
After Width: | Height: | Size: 29 KiB |
BIN
docs/images/lib-m_multiply-1.JPG
Normal file
After Width: | Height: | Size: 22 KiB |
BIN
docs/images/lib-m_rotation-1.JPG
Normal file
After Width: | Height: | Size: 37 KiB |
BIN
docs/images/lib-m_rotation-2.JPG
Normal file
After Width: | Height: | Size: 54 KiB |
BIN
docs/images/lib-m_scaling-1.JPG
Normal file
After Width: | Height: | Size: 41 KiB |
BIN
docs/images/lib-m_shearing-1.JPG
Normal file
After Width: | Height: | Size: 46 KiB |
BIN
docs/images/lib-m_translation-1.JPG
Normal file
After Width: | Height: | Size: 23 KiB |
BIN
docs/images/lib-rotate_p-3.JPG
Normal file
After Width: | Height: | Size: 31 KiB |
BIN
docs/images/lib-shear-1.JPG
Normal file
After Width: | Height: | Size: 46 KiB |
30
docs/lib-m_cumulate.md
Normal file
@ -0,0 +1,30 @@
|
||||
# m_cumulate
|
||||
|
||||
The power of using transformation matrice is that you can cumulate all transformations in a matrix. This function multipies all transformation matrice.
|
||||
|
||||
**Since:** 1.1
|
||||
|
||||
## Parameters
|
||||
|
||||
- `matrice` : A list of 4x4 transformation matrice.
|
||||
|
||||
## Examples
|
||||
|
||||
include <m_rotation.scad>;
|
||||
include <m_scaling.scad>;
|
||||
include <m_translation.scad>;
|
||||
include <m_cumulate.scad>
|
||||
|
||||
m = m_cumulate([
|
||||
m_translation([10, 20, 10]), m_scaling(2), m_rotation(60)]
|
||||
);
|
||||
|
||||
multmatrix(m)
|
||||
cube(1);
|
||||
|
||||
multmatrix(m)
|
||||
sphere(1);
|
||||
|
||||
|
||||
![m_cumulate](images/lib-m_cumulate-1.JPG)
|
||||
|
23
docs/lib-m_mirror.md
Normal file
@ -0,0 +1,23 @@
|
||||
# m_mirror
|
||||
|
||||
Generate a 4x4 transformation matrix which can pass into `multmatrix` to mirror the child element on a plane through the origin.
|
||||
|
||||
**Since:** 1.1
|
||||
|
||||
## Parameters
|
||||
|
||||
- `v` : The normal vector of a plane intersecting the origin through which to mirror the object.
|
||||
|
||||
## Examples
|
||||
|
||||
include <m_mirror.scad>;
|
||||
|
||||
rotate([0, 0, 10])
|
||||
cube([3, 2, 1]);
|
||||
|
||||
multmatrix(m_mirror([1, 1, 0]))
|
||||
rotate([0, 0, 10])
|
||||
cube([3, 2, 1]);
|
||||
|
||||
![m_mirror](images/lib-m_mirror-1.JPG)
|
||||
|
25
docs/lib-m_multiply.md
Normal file
@ -0,0 +1,25 @@
|
||||
# m_multiply
|
||||
|
||||
Multiply two 4x4 transformation matrice.
|
||||
|
||||
**Since:** 1.1
|
||||
|
||||
## Parameters
|
||||
|
||||
- `ma`, `mb` : Two 4x4 transformation matrice.
|
||||
|
||||
## Examples
|
||||
|
||||
include <m_multiply.scad>;
|
||||
include <m_scaling.scad>;
|
||||
include <m_rotation.scad>;
|
||||
|
||||
ma = m_scaling([0.5, 1, 2]);
|
||||
mb = m_rotation([0, 0, 90]);
|
||||
|
||||
cube(10);
|
||||
multmatrix(m_multiply(ma, mb))
|
||||
translate([15, 0, 0]) cube(10);
|
||||
|
||||
![m_multiply](images/lib-m_multiply-1.JPG)
|
||||
|
45
docs/lib-m_rotation.md
Normal file
@ -0,0 +1,45 @@
|
||||
# m_rotation
|
||||
|
||||
Generate a 4x4 transformation matrix which can pass into `multmatrix` to rotate the child element about the axis of the coordinate system or around an arbitrary axis.
|
||||
|
||||
**Since:** 1.1
|
||||
|
||||
## Parameters
|
||||
|
||||
- `a` : If it's `[deg_x, deg_y, deg_z]`, the rotation is applied in the order `x`, `y`, `z`. If it's `[deg_x, deg_y]`, the rotation is applied in the order `x`, `y`. If it's`[deg_x]`, the rotation is only applied to the `x` axis. If it's an number, the rotation is only applied to the `z` axis or an arbitrary axis.
|
||||
- `v`: A vector allows you to set an arbitrary axis about which the object will be rotated. When `a` is an array, the `v` argument is ignored.
|
||||
|
||||
## Examples
|
||||
|
||||
include <m_rotation.scad>;
|
||||
|
||||
point = [20, 0, 0];
|
||||
a = [0, -45, 45];
|
||||
|
||||
hull() {
|
||||
sphere(1);
|
||||
multmatrix(m_rotation(a))
|
||||
translate(point)
|
||||
sphere(1);
|
||||
}
|
||||
|
||||
![m_rotation](images/lib-m_rotation-1.JPG)
|
||||
|
||||
include <m_rotation.scad>;
|
||||
|
||||
v = [10, 10, 10];
|
||||
|
||||
hull() {
|
||||
sphere(1);
|
||||
translate(v)
|
||||
sphere(1);
|
||||
}
|
||||
|
||||
p = [10, 10, 0];
|
||||
for(i = [0:20:340]) {
|
||||
multmatrix(m_rotation(a = i, v = v))
|
||||
translate(p)
|
||||
sphere(1);
|
||||
}
|
||||
|
||||
![m_rotation](images/lib-m_rotation-2.JPG)
|
21
docs/lib-m_scaling.md
Normal file
@ -0,0 +1,21 @@
|
||||
# m_scaling
|
||||
|
||||
Generate a 4x4 transformation matrix which can pass into `multmatrix` to scale its child elements using the specified vector.
|
||||
|
||||
**Since:** 1.1
|
||||
|
||||
## Parameters
|
||||
|
||||
- `v` : Elements will be scaled using the vector.
|
||||
|
||||
## Examples
|
||||
|
||||
include <m_scaling.scad>;
|
||||
|
||||
cube(10);
|
||||
translate([15, 0, 0])
|
||||
multmatrix(m_scaling([0.5, 1, 2]))
|
||||
cube(10);
|
||||
|
||||
![m_scaling](images/lib-m_scaling-1.JPG)
|
||||
|
51
docs/lib-m_shearing.md
Normal file
@ -0,0 +1,51 @@
|
||||
# m_shearing
|
||||
|
||||
Generate a 4x4 transformation matrix which can pass into `multmatrix` to shear all child elements along the X-axis, Y-axis, or Z-axis in 3D.
|
||||
|
||||
**Since:** 1.1
|
||||
|
||||
## Parameters
|
||||
|
||||
- `sx` : An array `[SHy, SHz]`. The new coordinates of child elements are `(x + SHy * y + SHz * z, y, z)`.
|
||||
- `sy` : An array `[SHx, SHz]`. The new coordinates of child elements are `(x, y + SHx * x + SHz * z, z)`.
|
||||
- `sz` : An array `[SHx, SHy]`. The new coordinates of child elements are `(x, y, z + SHx * x + SHy * y)`.
|
||||
|
||||
## Examples
|
||||
|
||||
include <m_shearing.scad>;
|
||||
|
||||
color("red") {
|
||||
multmatrix(m_shearing(sx = [1, 0]))
|
||||
cube(1);
|
||||
|
||||
translate([2, 0, 0]) multmatrix(m_shearing(sx = [0, 1]))
|
||||
cube(1);
|
||||
|
||||
translate([4, 0, 0]) multmatrix(m_shearing(sx = [1, 1]))
|
||||
cube(1);
|
||||
}
|
||||
|
||||
translate([0, -3, 0]) color("green") {
|
||||
multmatrix(m_shearing(sy = [1, 0]))
|
||||
cube(1);
|
||||
|
||||
translate([2, 0, 0]) multmatrix(m_shearing(sy = [0, 1]))
|
||||
cube(1);
|
||||
|
||||
translate([4, 0, 0]) multmatrix(m_shearing(sy = [1, 1]))
|
||||
cube(1);
|
||||
}
|
||||
|
||||
translate([0, -5, 0]) color("blue") {
|
||||
multmatrix(m_shearing(sz = [1, 0]))
|
||||
cube(1);
|
||||
|
||||
translate([2, 0, 0]) multmatrix(m_shearing(sz = [0, 1]))
|
||||
cube(1);
|
||||
|
||||
translate([4, 0, 0]) multmatrix(m_shearing(sz = [1, 1]))
|
||||
cube(1);
|
||||
}
|
||||
|
||||
![m_shearing](images/lib-m_shearing-1.JPG)
|
||||
|
20
docs/lib-m_translation.md
Normal file
@ -0,0 +1,20 @@
|
||||
# m_translation
|
||||
|
||||
Generate a 4x4 transformation matrix which can pass into `multmatrix` to translates (moves) its child elements along the specified vector.
|
||||
|
||||
**Since:** 1.1
|
||||
|
||||
## Parameters
|
||||
|
||||
- `v` : Elements will be translated along the vector.
|
||||
|
||||
## Examples
|
||||
|
||||
include <m_translation.scad>;
|
||||
|
||||
cube(2, center = true);
|
||||
multmatrix(m_translation([5, 0, 0]))
|
||||
sphere(1,center = true);
|
||||
|
||||
![m_translation](images/lib-m_translation-1.JPG)
|
||||
|
@ -1,11 +1,12 @@
|
||||
# rotate_p
|
||||
|
||||
Rotates a point `a` degrees around an arbitrary axis. It behaves as the built-in `rotate` module
|
||||
Rotates a point `a` degrees about the axis of the coordinate system or around an arbitrary axis. It behaves as the built-in `rotate` module
|
||||
|
||||
## Parameters
|
||||
|
||||
- `point` : A 3D point `[x, y, z]` or a 2D point `[x, y]`.
|
||||
- `a` : If it's `[deg_x, deg_y, deg_z]`, the rotation is applied in the order `x`, `y`, `z`. If it's `[deg_x, deg_y]`, the rotation is applied in the order `x`, `y`. If it's`[deg_x]`, the rotation is only applied to the `x` axis. If it's an number, the rotation is only applied to the `z` axis.
|
||||
- `a` : If it's `[deg_x, deg_y, deg_z]`, the rotation is applied in the order `x`, `y`, `z`. If it's `[deg_x, deg_y]`, the rotation is applied in the order `x`, `y`. If it's`[deg_x]`, the rotation is only applied to the `x` axis. If it's an number, the rotation is only applied to the `z` axis or an arbitrary axis.
|
||||
- `v`: A vector allows you to set an arbitrary axis about which the object will be rotated. When `a` is an array, the `v` argument is ignored. **Since:** 1.1.
|
||||
|
||||
## Examples
|
||||
|
||||
@ -60,4 +61,22 @@ The `rotate_p` function is useful in some situations. For example, you probably
|
||||
|
||||
%sphere(radius);
|
||||
|
||||
![rotate_p](images/lib-rotate_p-2.JPG)
|
||||
![rotate_p](images/lib-rotate_p-2.JPG)
|
||||
|
||||
include <rotate_p.scad>;
|
||||
|
||||
v = [10, 10, 10];
|
||||
|
||||
hull() {
|
||||
sphere(1);
|
||||
translate(v)
|
||||
sphere(1);
|
||||
}
|
||||
|
||||
p = [10, 10, 0];
|
||||
for(i = [0:20:340]) {
|
||||
translate(rotate_p(p, a = i, v = v))
|
||||
sphere(1);
|
||||
}
|
||||
|
||||
![rotate_p](images/lib-rotate_p-3.JPG)
|
52
docs/lib-shear.md
Normal file
@ -0,0 +1,52 @@
|
||||
# shear
|
||||
|
||||
Shear all child elements along the X-axis, Y-axis, or Z-axis in 3D.
|
||||
|
||||
**Since:** 1.1
|
||||
|
||||
|
||||
## Parameters
|
||||
|
||||
- `sx` : An array `[SHy, SHz]`. The new coordinates of child elements are `(x + SHy * y + SHz * z, y, z)`.
|
||||
- `sy` : An array `[SHx, SHz]`. The new coordinates of child elements are `(x, y + SHx * x + SHz * z, z)`.
|
||||
- `sz` : An array `[SHx, SHy]`. The new coordinates of child elements are `(x, y, z + SHx * x + SHy * y)`.
|
||||
|
||||
## Examples
|
||||
|
||||
include <shear.scad>;
|
||||
|
||||
color("red") {
|
||||
shear(sx = [1, 0])
|
||||
cube(1);
|
||||
|
||||
translate([2, 0, 0]) shear(sx = [0, 1])
|
||||
cube(1);
|
||||
|
||||
translate([4, 0, 0]) shear(sx = [1, 1])
|
||||
cube(1);
|
||||
}
|
||||
|
||||
translate([0, -3, 0]) color("green") {
|
||||
shear(sy = [1, 0])
|
||||
cube(1);
|
||||
|
||||
translate([2, 0, 0]) shear(sy = [0, 1])
|
||||
cube(1);
|
||||
|
||||
translate([4, 0, 0]) shear(sy = [1, 1])
|
||||
cube(1);
|
||||
}
|
||||
|
||||
translate([0, -5, 0]) color("blue") {
|
||||
shear(sz = [1, 0])
|
||||
cube(1);
|
||||
|
||||
translate([2, 0, 0]) shear(sz = [0, 1])
|
||||
cube(1);
|
||||
|
||||
translate([4, 0, 0]) shear(sz = [1, 1])
|
||||
cube(1);
|
||||
}
|
||||
|
||||
![shear](images/lib-shear-1.JPG)
|
||||
|
@ -1,6 +0,0 @@
|
||||
function __length_between(p1, p2) =
|
||||
let(
|
||||
dx = p2[0] - p1[0],
|
||||
dy = p2[1] - p1[1],
|
||||
dz = p2[2] - p1[2]
|
||||
) sqrt(pow(dx, 2) + pow(dy, 2) + pow(dz, 2));
|
13
src/__private__/__m_multiply.scad
Normal file
@ -0,0 +1,13 @@
|
||||
function __m_multiply(ma, mb) =
|
||||
let(
|
||||
c1 = [mb[0][0], mb[1][0], mb[2][0], mb[3][0]],
|
||||
c2 = [mb[0][1], mb[1][1], mb[2][1], mb[3][1]],
|
||||
c3 = [mb[0][2], mb[1][2], mb[2][2], mb[3][2]],
|
||||
c4 = [mb[0][3], mb[1][3], mb[2][3], mb[3][3]]
|
||||
)
|
||||
[
|
||||
[ma[0] * c1, ma[0] * c2, ma[0] * c3, ma[0] * c4],
|
||||
[ma[1] * c1, ma[1] * c2, ma[1] * c3, ma[1] * c4],
|
||||
[ma[2] * c1, ma[2] * c2, ma[2] * c3, ma[2] * c4],
|
||||
[ma[3] * c1, ma[3] * c2, ma[3] * c3, ma[3] * c4]
|
||||
];
|
15
src/__private__/__m_shearing.scad
Normal file
@ -0,0 +1,15 @@
|
||||
function __m_shearing(sx, sy, sz) =
|
||||
let(
|
||||
sx_along_y = sx[0],
|
||||
sx_along_z = sx[1],
|
||||
sy_along_x = sy[0],
|
||||
sy_along_z = sy[1],
|
||||
sz_along_x = sz[0],
|
||||
sz_along_y = sz[1]
|
||||
)
|
||||
[
|
||||
[1, sx_along_y, sx_along_z, 0],
|
||||
[sy_along_x, 1, sy_along_z, 0],
|
||||
[sz_along_x, sz_along_y, 1, 0],
|
||||
[0, 0, 0, 1]
|
||||
];
|
@ -1,9 +1,6 @@
|
||||
/**
|
||||
* along_with.scad
|
||||
*
|
||||
* Puts children along the given path. If there's only one child,
|
||||
* it will put the child for each point.
|
||||
*
|
||||
* @copyright Justin Lin, 2017
|
||||
* @license https://opensource.org/licenses/lgpl-3.0.html
|
||||
*
|
||||
@ -14,6 +11,11 @@
|
||||
include <__private__/__angy_angz.scad>;
|
||||
include <__private__/__is_vector.scad>;
|
||||
include <__private__/__to3d.scad>;
|
||||
include <__private__/__m_multiply.scad>;
|
||||
|
||||
// Becuase of improving the performance, this module requires m_rotation.scad which doesn't require in dotSCAD 1.0.
|
||||
// For backward compatibility, I directly include m_rotation here.
|
||||
include <m_rotation.scad>;
|
||||
|
||||
module along_with(points, angles, twist = 0, scale = 1.0) {
|
||||
leng_points = len(points);
|
||||
@ -30,7 +32,44 @@ module along_with(points, angles, twist = 0, scale = 1.0) {
|
||||
(scale[1] - 1) / leng_points_minus_one,
|
||||
scale[2] == undef ? 0 : (scale[2] - 1) / leng_points_minus_one
|
||||
] : scale_step();
|
||||
|
||||
// get rotation matrice for sections
|
||||
|
||||
function local_ang_vects(j) =
|
||||
j == 0 ? [] : local_ang_vects_sub(j);
|
||||
|
||||
function local_ang_vects_sub(j) =
|
||||
let(
|
||||
vt0 = points[j] - points[j - 1],
|
||||
vt1 = points[j + 1] - points[j],
|
||||
a = acos((vt0 * vt1) / (norm(vt0) * norm(vt1))),
|
||||
v = cross(vt0, vt1)
|
||||
)
|
||||
concat([[a, v]], local_ang_vects(j - 1));
|
||||
|
||||
function cumulated_rot_matrice(i, rot_matrice) =
|
||||
let(
|
||||
leng_rot_matrice = len(rot_matrice),
|
||||
leng_rot_matrice_minus_one = leng_rot_matrice - 1,
|
||||
leng_rot_matrice_minus_two = leng_rot_matrice - 2
|
||||
)
|
||||
i == leng_rot_matrice - 2 ?
|
||||
[
|
||||
rot_matrice[leng_rot_matrice_minus_one],
|
||||
__m_multiply(rot_matrice[leng_rot_matrice_minus_two], rot_matrice[leng_rot_matrice_minus_one])
|
||||
]
|
||||
: cumulated_rot_matrice_sub(i, rot_matrice);
|
||||
|
||||
function cumulated_rot_matrice_sub(i, rot_matrice) =
|
||||
let(
|
||||
matrice = cumulated_rot_matrice(i + 1, rot_matrice),
|
||||
curr_matrix = rot_matrice[i],
|
||||
prev_matrix = matrice[len(matrice) - 1]
|
||||
)
|
||||
concat(matrice, [__m_multiply(curr_matrix, prev_matrix)]);
|
||||
|
||||
// align modules
|
||||
|
||||
module align_with_pts_angles(i) {
|
||||
translate(points[i])
|
||||
rotate(angles[i])
|
||||
@ -48,20 +87,17 @@ module along_with(points, angles, twist = 0, scale = 1.0) {
|
||||
children(0);
|
||||
}
|
||||
|
||||
module align_with_pts_local_rotate(j, init_a, init_s) {
|
||||
module align_with_pts_local_rotate(j, init_a, init_s, cumu_rot_matrice) {
|
||||
if(j == 0) { // first child
|
||||
align_with_pts_init(init_a, init_s)
|
||||
children(0);
|
||||
}
|
||||
else {
|
||||
vt0 = points[j] - points[j - 1];
|
||||
vt1 = points[j + 1] - points[j];
|
||||
a = acos((vt0 * vt1) / (norm(vt0) * norm(vt1)));
|
||||
rotate(a, cross(vt0, vt1))
|
||||
align_with_pts_local_rotate(j - 1, init_a, init_s)
|
||||
multmatrix(cumu_rot_matrice[j - 1])
|
||||
align_with_pts_init(init_a, init_s)
|
||||
children(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(angles != undef) {
|
||||
if($children == 1) {
|
||||
@ -75,23 +111,27 @@ module along_with(points, angles, twist = 0, scale = 1.0) {
|
||||
}
|
||||
}
|
||||
else {
|
||||
cumu_rot_matrice = cumulated_rot_matrice(0, [
|
||||
for(ang_vect = local_ang_vects(leng_points - 2))
|
||||
m_rotation(ang_vect[0], ang_vect[1])
|
||||
]);
|
||||
|
||||
translate(points[0])
|
||||
align_with_pts_local_rotate(0, 0, [1, 1, 1])
|
||||
align_with_pts_local_rotate(0, 0, [1, 1, 1], cumu_rot_matrice)
|
||||
children(0);
|
||||
|
||||
if($children == 1) {
|
||||
for(i = [0:leng_points - 2]) {
|
||||
translate(points[i + 1])
|
||||
align_with_pts_local_rotate(i, i * twist_step_a, [1, 1, 1] + scale_step_vt * i)
|
||||
align_with_pts_local_rotate(i, i * twist_step_a, [1, 1, 1] + scale_step_vt * i, cumu_rot_matrice)
|
||||
children(0);
|
||||
}
|
||||
} else {
|
||||
for(i = [0:min(leng_points, $children) - 2]) {
|
||||
translate(points[i + 1])
|
||||
align_with_pts_local_rotate(i, i * twist_step_a, [1, 1, 1] + scale_step_vt * i)
|
||||
align_with_pts_local_rotate(i, i * twist_step_a, [1, 1, 1] + scale_step_vt * i, cumu_rot_matrice)
|
||||
children(i + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,10 +1,6 @@
|
||||
/**
|
||||
* arc.scad
|
||||
*
|
||||
* Creates an arc. You can pass a 2 element vector to define the central angle.
|
||||
* Its $fa, $fs and $fn parameters are consistent with the circle module.
|
||||
* It depends on the circular_sector module so you have to include circular_sector.scad.
|
||||
*
|
||||
* @copyright Justin Lin, 2017
|
||||
* @license https://opensource.org/licenses/lgpl-3.0.html
|
||||
*
|
||||
|
@ -1,10 +1,6 @@
|
||||
/**
|
||||
* arc_shape.scad
|
||||
*
|
||||
* Creates an arc. You can pass a 2 element vector to define the central angle.
|
||||
* Its $fa, $fs and $fn parameters are consistent with the circle module.
|
||||
* It depends on the circular_sector module so you have to include circular_sector.scad.
|
||||
*
|
||||
* @copyright Justin Lin, 2017
|
||||
* @license https://opensource.org/licenses/lgpl-3.0.html
|
||||
*
|
||||
|
@ -1,17 +1,5 @@
|
||||
/**
|
||||
* archimedean_spiral.scad
|
||||
*
|
||||
* Gets all points and angles on the path of an archimedean spiral. The distance between two points is almost constant.
|
||||
*
|
||||
* It returns a vector of [[x, y], angle].
|
||||
*
|
||||
* In polar coordinates (r, <EFBFBD>c) Archimedean spiral can be described by the equation r = b<EFBFBD>c where
|
||||
* <EFBFBD>c is measured in radians. For being consistent with OpenSCAD, the function here use degrees.
|
||||
*
|
||||
* An init_angle less than 180 degrees is not recommended because the function uses an approximate
|
||||
* approach. If you really want an init_angle less than 180 degrees, a larger arm_distance
|
||||
* is required. To avoid a small error value at the calculated distance between two points, you
|
||||
* may try a smaller point_distance.
|
||||
*
|
||||
* @copyright Justin Lin, 2017
|
||||
* @license https://opensource.org/licenses/lgpl-3.0.html
|
||||
|
@ -1,8 +1,6 @@
|
||||
/**
|
||||
* archimedean_spiral_extrude.scad
|
||||
*
|
||||
* Extrudes a 2D shape along the path of a archimedean spiral.
|
||||
*
|
||||
* @copyright Justin Lin, 2017
|
||||
* @license https://opensource.org/licenses/lgpl-3.0.html
|
||||
*
|
||||
|
@ -1,7 +1,5 @@
|
||||
/**
|
||||
* bend.scad
|
||||
*
|
||||
* Bends a 3D object into an arc shape.
|
||||
*
|
||||
* @copyright Justin Lin, 2017
|
||||
* @license https://opensource.org/licenses/lgpl-3.0.html
|
||||
|
@ -1,10 +1,6 @@
|
||||
/**
|
||||
* bezier_curve.scad
|
||||
*
|
||||
* Given a set of control points, the bezier_curve function returns points of the Bézier path.
|
||||
* Combined with the polyline, polyline3d or hull_polyline3d module defined in my lib-openscad,
|
||||
* you can create a Bézier curve.
|
||||
*
|
||||
* @copyright Justin Lin, 2017
|
||||
* @license https://opensource.org/licenses/lgpl-3.0.html
|
||||
*
|
||||
|
@ -1,8 +1,6 @@
|
||||
/**
|
||||
* bezier_smooth.scad
|
||||
*
|
||||
* Given a path, the bezier_smooth function uses bazier curves to smooth all corners.
|
||||
*
|
||||
* @copyright Justin Lin, 2017
|
||||
* @license https://opensource.org/licenses/lgpl-3.0.html
|
||||
*
|
||||
|
@ -1,12 +1,6 @@
|
||||
/**
|
||||
* bezier_surface.scad
|
||||
*
|
||||
* Given a set of control points, the bezier_surface function returns points of the Bézier surface.
|
||||
* Combined with the function_grapher module defined in my lib-openscad,
|
||||
* you can create a Bézier surface.
|
||||
*
|
||||
* It depends on the bezier_curve function so remember to include bezier_curve.scad.
|
||||
*
|
||||
* @copyright Justin Lin, 2017
|
||||
* @license https://opensource.org/licenses/lgpl-3.0.html
|
||||
*
|
||||
|
@ -1,8 +1,6 @@
|
||||
/**
|
||||
* box_extrude.scad
|
||||
*
|
||||
* Creates a box (container) from a 2D object.
|
||||
*
|
||||
* @copyright Justin Lin, 2017
|
||||
* @license https://opensource.org/licenses/lgpl-3.0.html
|
||||
*
|
||||
|
@ -1,10 +1,6 @@
|
||||
/**
|
||||
* circle_path.scad
|
||||
*
|
||||
* Sometimes you need all points on the path of a circle. Here's
|
||||
* the function. Its $fa, $fs and $fn parameters are consistent
|
||||
* with the circle module.
|
||||
*
|
||||
* @copyright Justin Lin, 2017
|
||||
* @license https://opensource.org/licenses/lgpl-3.0.html
|
||||
*
|
||||
|
@ -1,9 +1,6 @@
|
||||
/**
|
||||
* cross_sections.scad
|
||||
*
|
||||
* Given a 2D shape, points and angles along the path, this function
|
||||
* will return all cross-sections.
|
||||
*
|
||||
* @copyright Justin Lin, 2017
|
||||
* @license https://opensource.org/licenses/lgpl-3.0.html
|
||||
*
|
||||
|
@ -1,8 +1,6 @@
|
||||
/**
|
||||
* crystal_ball.scad
|
||||
*
|
||||
* Uses Spherical coordinate system to create a crystal ball.
|
||||
*
|
||||
* @copyright Justin Lin, 2017
|
||||
* @license https://opensource.org/licenses/lgpl-3.0.html
|
||||
*
|
||||
|
@ -1,9 +1,6 @@
|
||||
/**
|
||||
* ellipse_extrude.scad
|
||||
*
|
||||
* Extrudes a 2D object along the path of an ellipse from 0 to 180 degrees.
|
||||
* The semi-major axis is not necessary because it's eliminated while calculating.
|
||||
*
|
||||
* @copyright Justin Lin, 2017
|
||||
* @license https://opensource.org/licenses/lgpl-3.0.html
|
||||
*
|
||||
|
@ -1,13 +1,6 @@
|
||||
/**
|
||||
* function_grapher.scad
|
||||
*
|
||||
*
|
||||
* Given a set of points `[x, y, f(x, y)]` where `f(x, y)` is a
|
||||
* mathematics function, the `function_grapher` module can
|
||||
* create the graph of `f(x, y)`.
|
||||
* It depends on the line3d, polyline3d, hull_polyline3d modules so you have
|
||||
* to include "line3d.scad", "polyline3d.scad", "hull_polyline3d.scad".
|
||||
*
|
||||
* @copyright Justin Lin, 2017
|
||||
* @license https://opensource.org/licenses/lgpl-3.0.html
|
||||
*
|
||||
|
@ -1,10 +1,6 @@
|
||||
/**
|
||||
* golden_spiral.scad
|
||||
*
|
||||
* Gets all points and angles on the path of a golden spiral. The distance between two points is almost constant.
|
||||
*
|
||||
* It returns a vector of [[x, y], angle].
|
||||
*
|
||||
* @copyright Justin Lin, 2017
|
||||
* @license https://opensource.org/licenses/lgpl-3.0.html
|
||||
*
|
||||
|
@ -1,8 +1,6 @@
|
||||
/**
|
||||
* golden_spiral_extrude.scad
|
||||
*
|
||||
* Extrudes a 2D shape along the path of a golden spiral.
|
||||
*
|
||||
* @copyright Justin Lin, 2017
|
||||
* @license https://opensource.org/licenses/lgpl-3.0.html
|
||||
*
|
||||
|
@ -1,10 +1,6 @@
|
||||
/**
|
||||
* helix.scad
|
||||
*
|
||||
* Gets all points on the path of a spiral around a cylinder.
|
||||
* Its $fa, $fs and $fn parameters are consistent with the cylinder module.
|
||||
* It depends on the circle_path module so you have to include circle_path.scad.
|
||||
*
|
||||
* @copyright Justin Lin, 2017
|
||||
* @license https://opensource.org/licenses/lgpl-3.0.html
|
||||
*
|
||||
|
@ -1,8 +1,6 @@
|
||||
/**
|
||||
* helix_extrude.scad
|
||||
*
|
||||
* Extrudes a 2D shape along a helix path.
|
||||
*
|
||||
* @copyright Justin Lin, 2017
|
||||
* @license https://opensource.org/licenses/lgpl-3.0.html
|
||||
*
|
||||
|
@ -1,9 +1,6 @@
|
||||
/**
|
||||
* hexagons.scad
|
||||
*
|
||||
* A hexagonal structure is useful in many situations.
|
||||
* This module creates hexagons in a hexagon.
|
||||
*
|
||||
* @copyright Justin Lin, 2017
|
||||
* @license https://opensource.org/licenses/lgpl-3.0.html
|
||||
*
|
||||
|
@ -1,8 +1,6 @@
|
||||
/**
|
||||
* hollow_out.scad
|
||||
*
|
||||
* Hollows out a 2D object.
|
||||
*
|
||||
* @copyright Justin Lin, 2017
|
||||
* @license https://opensource.org/licenses/lgpl-3.0.html
|
||||
*
|
||||
|
@ -1,10 +1,6 @@
|
||||
/**
|
||||
* hull_polyline2d.scad
|
||||
*
|
||||
* Creates a 2D polyline from a list of `[x, y]` coordinates.
|
||||
* As the name says, it uses the built-in hull operation for each pair of points (created by the circle module).
|
||||
* It's slow. However, it can be used to create metallic effects for a small $fn, large $fa or $fs.
|
||||
*
|
||||
* @copyright Justin Lin, 2017
|
||||
* @license https://opensource.org/licenses/lgpl-3.0.html
|
||||
*
|
||||
|
@ -1,10 +1,6 @@
|
||||
/**
|
||||
* hull_polyline3d.scad
|
||||
*
|
||||
* Creates a 3D polyline from a list of `[x, y, z]` coordinates.
|
||||
* As the name says, it uses the built-in hull operation for each pair of points (created by the sphere module).
|
||||
* It's slow. However, it can be used to create metallic effects for a small $fn, large $fa or $fs.
|
||||
*
|
||||
* @copyright Justin Lin, 2017
|
||||
* @license https://opensource.org/licenses/lgpl-3.0.html
|
||||
*
|
||||
|
@ -1,8 +1,6 @@
|
||||
/**
|
||||
* line2d.scad
|
||||
*
|
||||
* Creates a line from two points.
|
||||
*
|
||||
* @copyright Justin Lin, 2017
|
||||
* @license https://opensource.org/licenses/lgpl-3.0.html
|
||||
*
|
||||
|
@ -1,8 +1,6 @@
|
||||
/**
|
||||
* line3d.scad
|
||||
*
|
||||
* Creates a 3D line from two points.
|
||||
*
|
||||
* @copyright Justin Lin, 2017
|
||||
* @license https://opensource.org/licenses/lgpl-3.0.html
|
||||
*
|
||||
|
@ -1,8 +1,6 @@
|
||||
/**
|
||||
* log.scad
|
||||
*
|
||||
* A log module which supports simple level configurations and color titles.
|
||||
*
|
||||
* @copyright Justin Lin, 2017
|
||||
* @license https://opensource.org/licenses/lgpl-3.0.html
|
||||
*
|
||||
|
20
src/m_cumulate.scad
Normal file
@ -0,0 +1,20 @@
|
||||
/**
|
||||
* m_cumulate.scad
|
||||
*
|
||||
* @copyright Justin Lin, 2019
|
||||
* @license https://opensource.org/licenses/lgpl-3.0.html
|
||||
*
|
||||
* @see https://openhome.cc/eGossip/OpenSCAD/lib-m_cumulate.html
|
||||
*
|
||||
**/
|
||||
|
||||
include <__private__/__m_multiply.scad>;
|
||||
|
||||
function _m_cumulate(matrice, i) =
|
||||
i == len(matrice) - 2 ?
|
||||
__m_multiply(matrice[i], matrice[i + 1]) :
|
||||
__m_multiply(matrice[i], _m_cumulate(matrice, i + 1));
|
||||
|
||||
function m_cumulate(matrice) =
|
||||
len(matrice) == 1 ? matrice[0] : _m_cumulate(matrice, 0);
|
||||
|
26
src/m_mirror.scad
Normal file
@ -0,0 +1,26 @@
|
||||
/**
|
||||
* m_mirror.scad
|
||||
*
|
||||
* @copyright Justin Lin, 2019
|
||||
* @license https://opensource.org/licenses/lgpl-3.0.html
|
||||
*
|
||||
* @see https://openhome.cc/eGossip/OpenSCAD/lib-m_mirror.html
|
||||
*
|
||||
**/
|
||||
|
||||
function m_mirror(v) =
|
||||
let(
|
||||
nv = v / norm(v),
|
||||
txx = -2* nv[0] * nv[0],
|
||||
txy = -2* nv[0] * nv[1],
|
||||
txz = -2* nv[0] * nv[2],
|
||||
tyy = -2* nv[1] * nv[1],
|
||||
tyz = -2* nv[1] * nv[2],
|
||||
tzz = -2* nv[2] * nv[2]
|
||||
)
|
||||
[
|
||||
[1 + txx, txy, txz, 0],
|
||||
[txy, 1 + tyy, tyz, 0],
|
||||
[txz, tyz, 1 + tzz, 0],
|
||||
[0, 0, 0, 1]
|
||||
];
|
13
src/m_multiply.scad
Normal file
@ -0,0 +1,13 @@
|
||||
/**
|
||||
* m_multiply.scad
|
||||
*
|
||||
* @copyright Justin Lin, 2019
|
||||
* @license https://opensource.org/licenses/lgpl-3.0.html
|
||||
*
|
||||
* @see https://openhome.cc/eGossip/OpenSCAD/lib-m_multiply.html
|
||||
*
|
||||
**/
|
||||
|
||||
include <__private__/__m_multiply.scad>;
|
||||
|
||||
function m_multiply(ma, mb) = __m_multiply(ma, mb);
|
87
src/m_rotation.scad
Normal file
@ -0,0 +1,87 @@
|
||||
/**
|
||||
* m_rotation.scad
|
||||
*
|
||||
* @copyright Justin Lin, 2019
|
||||
* @license https://opensource.org/licenses/lgpl-3.0.html
|
||||
*
|
||||
* @see https://openhome.cc/eGossip/OpenSCAD/lib-m_rotation.html
|
||||
*
|
||||
**/
|
||||
|
||||
include <__private__/__m_multiply.scad>;
|
||||
|
||||
function _q_rotation(a, v) =
|
||||
let(
|
||||
half_a = a / 2,
|
||||
axis = v / norm(v),
|
||||
s = sin(half_a),
|
||||
x = s * axis[0],
|
||||
y = s * axis[1],
|
||||
z = s * axis[2],
|
||||
w = cos(half_a),
|
||||
|
||||
x2 = x + x,
|
||||
y2 = y + y,
|
||||
z2 = z + z,
|
||||
|
||||
xx = x * x2,
|
||||
yx = y * x2,
|
||||
yy = y * y2,
|
||||
zx = z * x2,
|
||||
zy = z * y2,
|
||||
zz = z * z2,
|
||||
wx = w * x2,
|
||||
wy = w * y2,
|
||||
wz = w * z2
|
||||
)
|
||||
[
|
||||
[1 - yy - zz, yx - wz, zx + wy, 0],
|
||||
[yx + wz, 1 - xx - zz, zy - wx, 0],
|
||||
[zx - wy, zy + wx, 1 - xx - yy, 0],
|
||||
[0, 0, 0, 1]
|
||||
];
|
||||
|
||||
function _m_xRotation(a) =
|
||||
let(c = cos(a), s = sin(a))
|
||||
[
|
||||
[1, 0, 0, 0],
|
||||
[0, c, -s, 0],
|
||||
[0, s, c, 0],
|
||||
[0, 0, 0, 1]
|
||||
];
|
||||
|
||||
function _m_yRotation(a) =
|
||||
let(c = cos(a), s = sin(a))
|
||||
[
|
||||
[c, 0, s, 0],
|
||||
[0, 1, 0, 0],
|
||||
[-s, 0, c, 0],
|
||||
[0, 0, 0, 1]
|
||||
];
|
||||
|
||||
function _m_zRotation(a) =
|
||||
let(c = cos(a), s = sin(a))
|
||||
[
|
||||
[c, -s, 0, 0],
|
||||
[s, c, 0, 0],
|
||||
[0, 0, 1, 0],
|
||||
[0, 0, 0, 1]
|
||||
];
|
||||
|
||||
function _to_avect(a) =
|
||||
len(a) == 3 ? a : (
|
||||
len(a) == 2 ? [a[0], a[1], 0] : (
|
||||
len(a) == 1 ? [a[0], 0, 0] : [0, 0, a]
|
||||
)
|
||||
);
|
||||
|
||||
function _xyz_rotation(a) =
|
||||
let(ang = _to_avect(a))
|
||||
__m_multiply(
|
||||
_m_zRotation(ang[2]), __m_multiply(
|
||||
_m_yRotation(ang[1]), _m_xRotation(ang[0])
|
||||
)
|
||||
);
|
||||
|
||||
function m_rotation(a, v) =
|
||||
v == undef ? _xyz_rotation(a) : _q_rotation(a, v);
|
25
src/m_scaling.scad
Normal file
@ -0,0 +1,25 @@
|
||||
/**
|
||||
* m_scaling.scad
|
||||
*
|
||||
* @copyright Justin Lin, 2019
|
||||
* @license https://opensource.org/licenses/lgpl-3.0.html
|
||||
*
|
||||
* @see https://openhome.cc/eGossip/OpenSCAD/lib-m_scaling.html
|
||||
*
|
||||
**/
|
||||
|
||||
function _to_svect(s) =
|
||||
len(s) == 3 ? s : (
|
||||
len(s) == 2 ? [s[0], s[1], 1] : (
|
||||
len(s) == 1 ? [s[0], 1, 1] : [s, s, s]
|
||||
)
|
||||
);
|
||||
|
||||
function m_scaling(s) =
|
||||
let(v = _to_svect(s))
|
||||
[
|
||||
[v[0], 0, 0, 0],
|
||||
[0, v[1], 0, 0],
|
||||
[0, 0, v[2], 0],
|
||||
[0, 0, 0, 1]
|
||||
];
|
14
src/m_shearing.scad
Normal file
@ -0,0 +1,14 @@
|
||||
/**
|
||||
* m_shearing.scad
|
||||
*
|
||||
* @copyright Justin Lin, 2019
|
||||
* @license https://opensource.org/licenses/lgpl-3.0.html
|
||||
*
|
||||
* @see https://openhome.cc/eGossip/OpenSCAD/lib-m_shearing.html
|
||||
*
|
||||
**/
|
||||
|
||||
include <__private__/__m_multiply.scad>;
|
||||
include <__private__/__m_shearing.scad>;
|
||||
|
||||
function m_shearing(sx = [0, 0], sy = [0, 0], sz = [0, 0]) = __m_shearing(sx, sy, sz);
|
25
src/m_translation.scad
Normal file
@ -0,0 +1,25 @@
|
||||
/**
|
||||
* m_translation.scad
|
||||
*
|
||||
* @copyright Justin Lin, 2019
|
||||
* @license https://opensource.org/licenses/lgpl-3.0.html
|
||||
*
|
||||
* @see https://openhome.cc/eGossip/OpenSCAD/lib-m_translation.html
|
||||
*
|
||||
**/
|
||||
|
||||
function _to_tvect(v) =
|
||||
len(v) == 3 ? v : (
|
||||
len(v) == 2 ? [v[0], v[1], 0] : (
|
||||
len(v) == 1 ? [v[0], 0, 0] : [v, 0, 0]
|
||||
)
|
||||
);
|
||||
|
||||
function m_translation(v) =
|
||||
let(vt = _to_tvect(v))
|
||||
[
|
||||
[1, 0, 0, vt[0]],
|
||||
[0, 1, 0, vt[1]],
|
||||
[0, 0, 1, vt[2]],
|
||||
[0, 0, 0, 1]
|
||||
];
|
@ -1,8 +1,6 @@
|
||||
/**
|
||||
* multi_line_text.scad
|
||||
*
|
||||
* Creates multi-line text from a list of strings.
|
||||
*
|
||||
* @copyright Justin Lin, 2017
|
||||
* @license https://opensource.org/licenses/lgpl-3.0.html
|
||||
*
|
||||
|
@ -1,10 +1,6 @@
|
||||
/**
|
||||
* parse_number.scad
|
||||
*
|
||||
* Parses the string argument as an number.
|
||||
* It depends on the split_str and the sub_str functions
|
||||
* so remember to include split_str.scad and sub_str.scad.
|
||||
*
|
||||
* @copyright Justin Lin, 2017
|
||||
* @license https://opensource.org/licenses/lgpl-3.0.html
|
||||
*
|
||||
|
@ -1,11 +1,6 @@
|
||||
/**
|
||||
* path_extrude.scad
|
||||
*
|
||||
* It extrudes a 2D shape along a path.
|
||||
* This module is suitable for a path created by a continuous function.
|
||||
* It depends on the rotate_p function and the polysections module.
|
||||
* Remember to include "rotate_p.scad" and "polysections.scad".
|
||||
*
|
||||
* @copyright Justin Lin, 2017
|
||||
* @license https://opensource.org/licenses/lgpl-3.0.html
|
||||
*
|
||||
@ -16,9 +11,14 @@
|
||||
include <__private__/__is_vector.scad>;
|
||||
include <__private__/__to3d.scad>;
|
||||
include <__private__/__angy_angz.scad>;
|
||||
include <__private__/__length_between.scad>;
|
||||
include <__private__/__m_multiply.scad>;
|
||||
|
||||
// Becuase of improving the performance, this module requires m_rotation.scad which doesn't require in dotSCAD 1.0.
|
||||
// For backward compatibility, I directly include m_rotation here.
|
||||
include <m_rotation.scad>;
|
||||
|
||||
module path_extrude(shape_pts, path_pts, triangles = "SOLID", twist = 0, scale = 1.0, closed = false) {
|
||||
// pre-process parameters
|
||||
function scale_pts(pts, s) = [
|
||||
for(p = pts) [p[0] * s[0], p[1] * s[1], p[2] * s[2]]
|
||||
];
|
||||
@ -45,8 +45,51 @@ module path_extrude(shape_pts, path_pts, triangles = "SOLID", twist = 0, scale =
|
||||
(scale[0] - 1) / len_path_pts_minus_one,
|
||||
(scale[1] - 1) / len_path_pts_minus_one,
|
||||
scale[2] == undef ? 0 : (scale[2] - 1) / len_path_pts_minus_one
|
||||
] : scale_step();
|
||||
] : scale_step();
|
||||
|
||||
// get rotation matrice for sections
|
||||
|
||||
function local_ang_vects(j) =
|
||||
j == 0 ? [] : local_ang_vects_sub(j);
|
||||
|
||||
function local_ang_vects_sub(j) =
|
||||
let(
|
||||
vt0 = pth_pts[j] - pth_pts[j - 1],
|
||||
vt1 = pth_pts[j + 1] - pth_pts[j],
|
||||
a = acos((vt0 * vt1) / (norm(vt0) * norm(vt1))),
|
||||
v = cross(vt0, vt1)
|
||||
)
|
||||
concat([[a, v]], local_ang_vects(j - 1));
|
||||
|
||||
rot_matrice = [
|
||||
for(ang_vect = local_ang_vects(len_path_pts - 2))
|
||||
m_rotation(ang_vect[0], ang_vect[1])
|
||||
];
|
||||
|
||||
leng_rot_matrice = len(rot_matrice);
|
||||
leng_rot_matrice_minus_one = leng_rot_matrice - 1;
|
||||
leng_rot_matrice_minus_two= leng_rot_matrice - 2;
|
||||
|
||||
function cumulated_rot_matrice(i) =
|
||||
i == leng_rot_matrice - 2 ?
|
||||
[
|
||||
rot_matrice[leng_rot_matrice_minus_one],
|
||||
__m_multiply(rot_matrice[leng_rot_matrice_minus_two], rot_matrice[leng_rot_matrice_minus_one])
|
||||
]
|
||||
: cumulated_rot_matrice_sub(i);
|
||||
|
||||
function cumulated_rot_matrice_sub(i) =
|
||||
let(
|
||||
matrice = cumulated_rot_matrice(i + 1),
|
||||
curr_matrix = rot_matrice[i],
|
||||
prev_matrix = matrice[len(matrice) - 1]
|
||||
)
|
||||
concat(matrice, [__m_multiply(curr_matrix, prev_matrix)]);
|
||||
|
||||
cumu_rot_matrice = cumulated_rot_matrice(0);
|
||||
|
||||
// get all sections
|
||||
|
||||
function init_section(a, s) =
|
||||
let(angleyz = __angy_angz(pth_pts[0], pth_pts[1]))
|
||||
rotate_pts(
|
||||
@ -66,14 +109,17 @@ module path_extrude(shape_pts, path_pts, triangles = "SOLID", twist = 0, scale =
|
||||
let(
|
||||
vt0 = pth_pts[j] - pth_pts[j - 1],
|
||||
vt1 = pth_pts[j + 1] - pth_pts[j],
|
||||
a = acos((vt0 * vt1) / (norm(vt0) * norm(vt1)))
|
||||
ms = cumu_rot_matrice[j - 1]
|
||||
)
|
||||
rotate_pts(
|
||||
local_rotate_section(j - 1, init_a, init_s),
|
||||
a,
|
||||
cross(vt0, vt1)
|
||||
);
|
||||
|
||||
[
|
||||
for(p = init_section(init_a, init_s))
|
||||
[
|
||||
[ms[0][0], ms[0][1], ms[0][2]] * p,
|
||||
[ms[1][0], ms[1][1], ms[1][2]] * p,
|
||||
[ms[2][0], ms[2][1], ms[2][2]] * p
|
||||
]
|
||||
];
|
||||
|
||||
function sections() =
|
||||
let(
|
||||
fst_section =
|
||||
@ -93,7 +139,7 @@ module path_extrude(shape_pts, path_pts, triangles = "SOLID", twist = 0, scale =
|
||||
sects = sections();
|
||||
|
||||
function calculated_sections() =
|
||||
closed && pth_pts[0] == pth_pts[len_path_pts - 1] ?
|
||||
closed && pth_pts[0] == pth_pts[len_path_pts_minus_one] ?
|
||||
concat(sects, [sects[0]]) : // round-robin
|
||||
sects;
|
||||
|
||||
|
@ -1,8 +1,6 @@
|
||||
/**
|
||||
* paths2sections.scad
|
||||
*
|
||||
* Given a list of paths, this function will return all cross-sections described by those paths.
|
||||
*
|
||||
* @copyright Justin Lin, 2017
|
||||
* @license https://opensource.org/licenses/lgpl-3.0.html
|
||||
*
|
||||
|
@ -1,8 +1,6 @@
|
||||
/**
|
||||
* pie.scad
|
||||
*
|
||||
* Creates a pie (circular sector). You can pass a 2 element vector to define the central angle. Its $fa, $fs and $fn parameters are consistent with the circle module.
|
||||
*
|
||||
* @copyright Justin Lin, 2017
|
||||
* @license https://opensource.org/licenses/lgpl-3.0.html
|
||||
*
|
||||
|
@ -1,10 +1,6 @@
|
||||
/**
|
||||
* polyline2d.scad
|
||||
*
|
||||
* Creates a polyline from a list of x, y coordinates. When the end points are CAP_ROUND,
|
||||
* you can use $fa, $fs or $fn to controll the circle module used internally.
|
||||
* It depends on the line2d module so you have to include line2d.scad.
|
||||
*
|
||||
* @copyright Justin Lin, 2017
|
||||
* @license https://opensource.org/licenses/lgpl-3.0.html
|
||||
*
|
||||
|
@ -1,9 +1,6 @@
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
|
@ -1,9 +1,6 @@
|
||||
/**
|
||||
* polysections.scad
|
||||
*
|
||||
* Crosscutting a tube-like shape at different points gets several cross-sections.
|
||||
* This module can operate reversely. It uses cross-sections to construct a tube-like shape.
|
||||
*
|
||||
* @copyright Justin Lin, 2017
|
||||
* @license https://opensource.org/licenses/lgpl-3.0.html
|
||||
*
|
||||
|
@ -1,9 +1,6 @@
|
||||
/**
|
||||
* polytransversals.scad
|
||||
*
|
||||
* Crosscutting a polyline at different points gets several transversals.
|
||||
* This module can operate reversely. It uses transversals to construct a polyline.
|
||||
*
|
||||
* @copyright Justin Lin, 2017
|
||||
* @license https://opensource.org/licenses/lgpl-3.0.html
|
||||
*
|
||||
|
@ -1,9 +1,6 @@
|
||||
/**
|
||||
* ring_extrude.scad
|
||||
*
|
||||
* Rotational extrusion spins a 2D shape around the Z-axis.
|
||||
* It's similar to the built-in `rotate_extrude`; however, it supports angle, twist and scale options.
|
||||
*
|
||||
* @copyright Justin Lin, 2017
|
||||
* @license https://opensource.org/licenses/lgpl-3.0.html
|
||||
*
|
||||
|
@ -1,9 +1,6 @@
|
||||
/**
|
||||
* rotate_p.scad
|
||||
*
|
||||
* Rotates a point 'a' degrees around an arbitrary axis.
|
||||
* The rotation is applied in the following order: x, y, z.
|
||||
*
|
||||
* @copyright Justin Lin, 2017
|
||||
* @license https://opensource.org/licenses/lgpl-3.0.html
|
||||
*
|
||||
@ -72,7 +69,7 @@ function _rotz(pt, a) =
|
||||
function _rotate_p_3d(point, a) =
|
||||
_rotz(_roty(_rotx(point, a[0]), a[1]), a[2]);
|
||||
|
||||
function to_avect(a) =
|
||||
function _to_avect(a) =
|
||||
len(a) == 3 ? a : (
|
||||
len(a) == 2 ? [a[0], a[1], 0] : (
|
||||
len(a) == 1 ? [a[0], 0, 0] : [0, 0, a]
|
||||
@ -80,7 +77,7 @@ function to_avect(a) =
|
||||
);
|
||||
|
||||
function _rotate_p(p, a) =
|
||||
let(angle = to_avect(a))
|
||||
let(angle = _to_avect(a))
|
||||
len(p) == 3 ?
|
||||
_rotate_p_3d(p, angle) :
|
||||
__to2d(
|
||||
|
@ -1,9 +1,6 @@
|
||||
/**
|
||||
* rounded_cube.scad
|
||||
*
|
||||
* Creates a rounded cube in the first octant.
|
||||
* When center is true, the cube is centered on the origin.
|
||||
*
|
||||
* @copyright Justin Lin, 2017
|
||||
* @license https://opensource.org/licenses/lgpl-3.0.html
|
||||
*
|
||||
|
@ -1,8 +1,6 @@
|
||||
/**
|
||||
* rounded_cylinder.scad
|
||||
*
|
||||
* Creates a rounded cylinder.
|
||||
*
|
||||
* @copyright Justin Lin, 2017
|
||||
* @license https://opensource.org/licenses/lgpl-3.0.html
|
||||
*
|
||||
|
@ -1,8 +1,6 @@
|
||||
/**
|
||||
* rounded_extrude.scad
|
||||
*
|
||||
* Extrudes a 2D object roundly from 0 to 180 degrees.
|
||||
*
|
||||
* @copyright Justin Lin, 2017
|
||||
* @license https://opensource.org/licenses/lgpl-3.0.html
|
||||
*
|
||||
|
@ -1,9 +1,6 @@
|
||||
/**
|
||||
* rounded_square.scad
|
||||
*
|
||||
* Creates a rounded square or rectangle in the first quadrant.
|
||||
* When center is true the square is centered on the origin.
|
||||
*
|
||||
* @copyright Justin Lin, 2017
|
||||
* @license https://opensource.org/licenses/lgpl-3.0.html
|
||||
*
|
||||
|
@ -1,10 +1,6 @@
|
||||
/**
|
||||
* shape_arc.scad
|
||||
*
|
||||
* Returns shape points of an arc shape.
|
||||
* They can be used with xxx_extrude modules of dotSCAD.
|
||||
* The shape points can be also used with the built-in polygon module.
|
||||
*
|
||||
* @copyright Justin Lin, 2017
|
||||
* @license https://opensource.org/licenses/lgpl-3.0.html
|
||||
*
|
||||
|
@ -1,10 +1,6 @@
|
||||
/**
|
||||
* shape_cyclicpolygon.scad
|
||||
*
|
||||
* Returns shape points of a regular cyclic polygon.
|
||||
* They can be used with xxx_extrude modules of dotSCAD.
|
||||
* The shape points can be also used with the built-in polygon module.
|
||||
*
|
||||
* @copyright Justin Lin, 2017
|
||||
* @license https://opensource.org/licenses/lgpl-3.0.html
|
||||
*
|
||||
|
@ -1,10 +1,6 @@
|
||||
/**
|
||||
* shape_ellipse.scad
|
||||
*
|
||||
* Returns shape points of an ellipse.
|
||||
* They can be used with xxx_extrude modules of dotSCAD.
|
||||
* The shape points can be also used with the built-in polygon module.
|
||||
*
|
||||
* @copyright Justin Lin, 2017
|
||||
* @license https://opensource.org/licenses/lgpl-3.0.html
|
||||
*
|
||||
|
@ -2,10 +2,6 @@
|
||||
/**
|
||||
* shape_glued2circles.scad
|
||||
*
|
||||
* Returns shape points of two glued circles.
|
||||
* They can be used with xxx_extrude modules of dotSCAD.
|
||||
* The shape points can be also used with the built-in polygon module.
|
||||
*
|
||||
* @copyright Justin Lin, 2017
|
||||
* @license https://opensource.org/licenses/lgpl-3.0.html
|
||||
*
|
||||
|
@ -1,11 +1,6 @@
|
||||
/**
|
||||
* shape_path_extend.scad
|
||||
*
|
||||
* It extends a 2D stroke along a path.
|
||||
* This module is suitable for a path created by a continuous function.
|
||||
* It depends on the rotate_p function and the polytransversals module.
|
||||
* Remember to include "rotate_p.scad" and "polytransversals.scad".
|
||||
*
|
||||
* @copyright Justin Lin, 2017
|
||||
* @license https://opensource.org/licenses/lgpl-3.0.html
|
||||
*
|
||||
@ -14,7 +9,6 @@
|
||||
**/
|
||||
|
||||
include <__private__/__to3d.scad>;
|
||||
include <__private__/__length_between.scad>;
|
||||
include <__private__/__polytransversals.scad>;
|
||||
include <__private__/__reverse.scad>;
|
||||
|
||||
@ -39,7 +33,7 @@ function _shape_path_first_stroke(stroke_pts, path_pts) =
|
||||
|
||||
function _shape_path_extend_stroke(stroke_pts, p1, p2, scale_step, i) =
|
||||
let(
|
||||
leng = __length_between(__to3d(p1), __to3d(p2)),
|
||||
leng = norm(__to3d(p2) - __to3d(p1)),
|
||||
a = _shape_path_extend_az(p1, p2)
|
||||
)
|
||||
[
|
||||
|
@ -1,10 +1,6 @@
|
||||
/**
|
||||
* shape_pentagram.scad
|
||||
*
|
||||
* Returns shape points of a pentagram.
|
||||
* They can be used with xxx_extrude modules of dotSCAD.
|
||||
* The shape points can be also used with the built-in polygon module.
|
||||
*
|
||||
* @copyright Justin Lin, 2017
|
||||
* @license https://opensource.org/licenses/lgpl-3.0.html
|
||||
*
|
||||
|
@ -1,10 +1,6 @@
|
||||
/**
|
||||
* shape_pie.scad
|
||||
*
|
||||
* Returns shape points of a pie (circular sector) shape.
|
||||
* They can be used with xxx_extrude modules of dotSCAD.
|
||||
* The shape points can be also used with the built-in polygon module.
|
||||
*
|
||||
* @copyright Justin Lin, 2017
|
||||
* @license https://opensource.org/licenses/lgpl-3.0.html
|
||||
*
|
||||
|
@ -1,10 +1,6 @@
|
||||
/**
|
||||
* shape_square.scad
|
||||
*
|
||||
* Returns shape points of a rounded square or rectangle.
|
||||
* They can be used with xxx_extrude modules of dotSCAD.
|
||||
* The shape points can be also used with the built-in polygon module.
|
||||
*
|
||||
* @copyright Justin Lin, 2017
|
||||
* @license https://opensource.org/licenses/lgpl-3.0.html
|
||||
*
|
||||
|
@ -1,10 +1,6 @@
|
||||
/**
|
||||
* shape_star.scad
|
||||
*
|
||||
* Returns shape points of a starburst.
|
||||
* They can be used with xxx_extrude modules of dotSCAD.
|
||||
* The shape points can be also used with the built-in polygon module.
|
||||
*
|
||||
* @copyright Justin Lin, 2017
|
||||
* @license https://opensource.org/licenses/lgpl-3.0.html
|
||||
*
|
||||
|
@ -1,10 +1,6 @@
|
||||
/**
|
||||
* shape_superformula.scad
|
||||
*
|
||||
* Returns shape points of a Superformula shape.
|
||||
* They can be used with xxx_extrude modules of dotSCAD.
|
||||
* The shape points can be also used with the built-in polygon module.
|
||||
*
|
||||
* @copyright Justin Lin, 2017
|
||||
* @license https://opensource.org/licenses/lgpl-3.0.html
|
||||
*
|
||||
|
@ -1,10 +1,6 @@
|
||||
/**
|
||||
* shape_taiwan.scad
|
||||
*
|
||||
* Returns shape points of Taiwan.
|
||||
* They can be used with xxx_extrude modules of dotSCAD.
|
||||
* The shape points can be also used with the built-in polygon module.
|
||||
*
|
||||
* @copyright Justin Lin, 2017
|
||||
* @license https://opensource.org/licenses/lgpl-3.0.html
|
||||
*
|
||||
|
@ -1,10 +1,6 @@
|
||||
/**
|
||||
* shape_trapezium.scad
|
||||
*
|
||||
* Returns shape points of an isosceles trapezium.
|
||||
* They can be used with xxx_extrude modules of dotSCAD.
|
||||
* The shape points can be also used with the built-in polygon module.
|
||||
*
|
||||
* @copyright Justin Lin, 2017
|
||||
* @license https://opensource.org/licenses/lgpl-3.0.html
|
||||
*
|
||||
|
16
src/shear.scad
Normal file
@ -0,0 +1,16 @@
|
||||
/**
|
||||
* shear.scad
|
||||
*
|
||||
* @copyright Justin Lin, 2019
|
||||
* @license https://opensource.org/licenses/lgpl-3.0.html
|
||||
*
|
||||
* @see https://openhome.cc/eGossip/OpenSCAD/lib-shear.html
|
||||
*
|
||||
**/
|
||||
|
||||
include <__private__/__m_multiply.scad>;
|
||||
include <__private__/__m_shearing.scad>;
|
||||
|
||||
module shear(sx = [0, 0], sy = [0, 0], sz = [0, 0]) {
|
||||
multmatrix(__m_shearing(sx, sy, sz)) children();
|
||||
}
|
@ -1,11 +1,6 @@
|
||||
/**
|
||||
* sphere_spiral.scad
|
||||
*
|
||||
* Creates all points and angles on the path of a spiral around a sphere.
|
||||
* It returns a vector of [[x, y, z], [ax, ay, az]]. [x, y, z] is actually
|
||||
* obtained from rotating [radius, 0, 0] by [ax, ay, az].
|
||||
* It depends on the rotate_p function. Remember to include rotate_p.scad first.
|
||||
*
|
||||
* @copyright Justin Lin, 2017
|
||||
* @license https://opensource.org/licenses/lgpl-3.0.html
|
||||
*
|
||||
|
@ -1,8 +1,6 @@
|
||||
/**
|
||||
* sphere_spiral_extrude.scad
|
||||
*
|
||||
* Extrudes a 2D shape along the path of a sphere spiral.
|
||||
*
|
||||
* @copyright Justin Lin, 2017
|
||||
* @license https://opensource.org/licenses/lgpl-3.0.html
|
||||
*
|
||||
|
@ -1,9 +1,6 @@
|
||||
/**
|
||||
* split_str.scad
|
||||
*
|
||||
* Splits the given string around matches of the given delimiting character.
|
||||
* It depends on the sub_str function so remember to include sub_str.scad.
|
||||
*
|
||||
* @copyright Justin Lin, 2017
|
||||
* @license https://opensource.org/licenses/lgpl-3.0.html
|
||||
*
|
||||
|
@ -1,11 +1,6 @@
|
||||
/**
|
||||
* stereographic_extrude.scad
|
||||
*
|
||||
* Takes a 2D polygon as input and extends it onto a sphere.
|
||||
* If you light up a lamp on the north pole of the sphere, the
|
||||
* shadow will return to the original 2D polygon. For more
|
||||
* information, take a look at [Stereographic projection](https://en.wikipedia.org/wiki/Stereographic_projection).
|
||||
*
|
||||
* @copyright Justin Lin, 2017
|
||||
* @license https://opensource.org/licenses/lgpl-3.0.html
|
||||
*
|
||||
|
@ -1,8 +1,6 @@
|
||||
/**
|
||||
* sub_str.scad
|
||||
*
|
||||
* Returns a new string that is a substring of the given string.
|
||||
*
|
||||
* @copyright Justin Lin, 2017
|
||||
* @license https://opensource.org/licenses/lgpl-3.0.html
|
||||
*
|
||||
|
@ -1,9 +1,6 @@
|
||||
/**
|
||||
* turtle2d.scad
|
||||
*
|
||||
* An OpenSCAD implementation of Turtle Graphics.
|
||||
* It moves on the xy plane.
|
||||
*
|
||||
* @copyright Justin Lin, 2017
|
||||
* @license https://opensource.org/licenses/lgpl-3.0.html
|
||||
*
|
||||
|
@ -1,8 +1,6 @@
|
||||
/**
|
||||
* turtle3d.scad
|
||||
*
|
||||
* An OpenSCAD implementation of 3D Turtle Graphics.
|
||||
*
|
||||
* @copyright Justin Lin, 2017
|
||||
* @license https://opensource.org/licenses/lgpl-3.0.html
|
||||
*
|
||||
|