1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-09-15 09:02:12 +02:00

63 Commits
v1.1 ... v1.2

Author SHA1 Message Date
Justin Lin
81e4f45f89 update doc 2019-05-21 21:42:53 +08:00
Justin Lin
46ffc7601d update doc 2019-05-21 21:09:13 +08:00
Justin Lin
31dba8711d reverse calculated sections 2019-05-21 20:50:57 +08:00
Justin Lin
ad983b8670 reverse shape_pts directly 2019-05-21 20:25:58 +08:00
Justin Lin
0d35fc2023 update RELEASE 2019-05-21 20:01:58 +08:00
Justin Lin
6851464068 fix CCW bug 2019-05-21 19:47:34 +08:00
Justin Lin
b9d93bac84 fix wrong funcall 2019-05-21 19:12:31 +08:00
Justin Lin
645d0946c1 remove re-asigned 2019-05-21 18:54:02 +08:00
Justin Lin
844c6e7d9b add comments 2019-05-20 17:40:02 +08:00
Justin Lin
5597fa0ce1 update README 2019-05-20 17:37:50 +08:00
Justin Lin
64eaa6d7e1 update README 2019-05-20 17:37:42 +08:00
Justin Lin
840fc0eac5 update RELEASE 2019-05-20 17:36:29 +08:00
Justin Lin
98bac0bdff update RELEASE 2019-05-20 17:36:04 +08:00
Justin Lin
8f747f2e75 update featured pic 2019-05-20 17:28:12 +08:00
Justin Lin
4e3016859c update doc 2019-05-20 17:20:08 +08:00
Justin Lin
7c38ea2009 add doc 2019-05-20 15:46:21 +08:00
Justin Lin
ce4d11cf52 update doc 2019-05-20 15:12:03 +08:00
Justin Lin
b4e4f60902 update doc 2019-05-20 15:04:23 +08:00
Justin Lin
feb0e351b6 add doc 2019-05-20 15:04:13 +08:00
Justin Lin
e670ad6b9d update docs 2019-05-20 15:04:05 +08:00
Justin Lin
bf1cc23f0f update docs 2019-05-20 14:21:59 +08:00
Justin Lin
fa966bdde8 update doc 2019-05-20 12:00:45 +08:00
Justin Lin
db8792fc4e update doc 2019-05-20 11:47:27 +08:00
Justin Lin
7d5e18ff8c add doc 2019-05-20 11:10:39 +08:00
Justin Lin
8722f971ba add doc 2019-05-20 11:01:57 +08:00
Justin Lin
6c0a0bdfb0 update doc 2019-05-20 10:55:53 +08:00
Justin Lin
156e15bc99 rename 2019-05-20 10:48:57 +08:00
Justin Lin
b2a521a11f update RELEASE 2019-05-19 20:43:34 +08:00
Justin Lin
597551e24a remove comment 2019-05-19 11:26:21 +08:00
Justin Lin
bf9a23d5c5 added bijection_offset 2019-05-19 09:50:36 +08:00
Justin Lin
cbf59ce0b4 remove repeating points 2019-05-19 09:28:01 +08:00
Justin Lin
fafa551959 added torus_knot 2019-05-17 17:59:08 +08:00
Justin Lin
63dcbe259d added starburst 2019-05-17 17:54:28 +08:00
Justin Lin
4ea52e328e rename 2019-05-17 13:01:57 +08:00
Justin Lin
1a92c27b28 added edge_aligned_sections 2019-05-17 10:00:04 +08:00
Justin Lin
a3e2077b46 update README 2019-05-15 20:09:36 +08:00
Justin Lin
afa0e99fe5 use __is_float 2019-05-15 19:51:52 +08:00
Justin Lin
09016a31cd missed _edge_r.scad 2019-05-15 19:41:43 +08:00
Justin Lin
ec102fbdee use __is_float 2019-05-15 19:38:09 +08:00
Justin Lin
106695b988 use __is__float 2019-05-15 19:35:42 +08:00
Justin Lin
ee31927015 use __is_float 2019-05-15 19:31:29 +08:00
Justin Lin
e60c451033 use __is_float 2019-05-15 19:26:47 +08:00
Justin Lin
53b7d7a628 refactor 2019-05-15 19:23:26 +08:00
Justin Lin
77b3c4c9db refactor 2019-05-15 19:20:50 +08:00
Justin Lin
bc7f57813b rename 2019-05-15 19:18:00 +08:00
Justin Lin
ad4a992c9d refactor 2019-05-15 19:16:00 +08:00
Justin Lin
f8f7adbb45 refactor 2019-05-15 19:14:21 +08:00
Justin Lin
f690952f1f refactor 2019-05-15 19:12:18 +08:00
Justin Lin
ac209d6125 use __is_float 2019-05-15 19:09:27 +08:00
Justin Lin
5d394d8738 check vector 2019-05-15 09:29:21 +08:00
Justin Lin
b3ffb9ab72 check vector 2019-05-15 09:26:58 +08:00
Justin Lin
665fb09864 update RELEASE 2019-05-13 09:55:25 +08:00
Justin Lin
f33d6c5671 consider two or three points 2019-05-13 09:50:53 +08:00
Justin Lin
f985e13231 remove echo 2019-05-13 09:47:35 +08:00
Justin Lin
7b1a683c74 consider two or three pts 2019-05-13 09:44:31 +08:00
Justin Lin
ff8d36336e add more check 2019-05-13 09:13:31 +08:00
Justin Lin
49be3b9b9f typo 2019-05-13 08:44:54 +08:00
Justin Lin
e13abc57ce update RELEASE 2019-05-13 08:41:50 +08:00
Justin Lin
6fbe42ba8f if a== 0 do_noting 2019-05-13 08:27:02 +08:00
Justin Lin
48e52fa48b update doc 2019-05-10 14:09:39 +08:00
Justin Lin
0dbe93d16b update doc 2019-05-08 13:57:46 +08:00
Justin Lin
bdaa05823c update doc 2019-05-07 17:38:38 +08:00
Justin Lin
035e1fa1b4 use built-in matrix multi 2019-05-07 17:35:32 +08:00
60 changed files with 614 additions and 171 deletions

View File

@@ -1,8 +1,8 @@
# dotSCAD 1.1
# dotSCAD 1.2
> Helpful modules and functions when playing OpenSCAD.
> Helpful modules and functions when playing OpenSCAD. Based on OpenSCAD 2015.03.
![dotSCAD](GoldenTaiwan.JPG)
![dotSCAD](WhirlingTaiwan.JPG)
[![license/LGPL](https://img.shields.io/badge/license-LGPL-blue.svg)](https://github.com/JustinSDK/lib-openscad/blob/master/LICENSE)
@@ -49,6 +49,7 @@ Too many dependencies? Because OpenSCAD doesn't provide namespace management, I
- [hull_polyline3d](https://openhome.cc/eGossip/OpenSCAD/lib-hull_polyline3d.html)
- [function_grapher](https://openhome.cc/eGossip/OpenSCAD/lib-function_grapher.html)
- [polysections](https://openhome.cc/eGossip/OpenSCAD/lib-polysections.html)
- [starburst](https://openhome.cc/eGossip/OpenSCAD/lib-starburst.html)
- Transformation
- [along_with](https://openhome.cc/eGossip/OpenSCAD/lib-along_with.html)
@@ -63,6 +64,8 @@ Too many dependencies? Because OpenSCAD doesn't provide namespace management, I
- [parse_number](https://openhome.cc/eGossip/OpenSCAD/lib-parse_number.html)
- [cross_sections](https://openhome.cc/eGossip/OpenSCAD/lib-cross_sections.html)
- [paths2sections](https://openhome.cc/eGossip/OpenSCAD/lib-paths2sections.html)
- [path_scaling_sections](https://openhome.cc/eGossip/OpenSCAD/lib-path_scaling_sections.html)
- [bijection_offset](https://openhome.cc/eGossip/OpenSCAD/lib-bijection_offset.html)
- Path
- [arc_path](https://openhome.cc/eGossip/OpenSCAD/lib-arc_path.html)
@@ -74,6 +77,7 @@ Too many dependencies? Because OpenSCAD doesn't provide namespace management, I
- [golden_spiral](https://openhome.cc/eGossip/OpenSCAD/lib-golden_spiral.html)
- [archimedean_spiral](https://openhome.cc/eGossip/OpenSCAD/lib-archimedean_spiral.html)
- [sphere_spiral](https://openhome.cc/eGossip/OpenSCAD/lib-sphere_spiral.html)
- [torus_knot](https://openhome.cc/eGossip/OpenSCAD/lib-torus_knot.html)
- Extrusion
- [box_extrude](https://openhome.cc/eGossip/OpenSCAD/lib-box_extrude.html)
@@ -104,7 +108,6 @@ Too many dependencies? Because OpenSCAD doesn't provide namespace management, I
- [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)

View File

@@ -1,3 +1,28 @@
> Version numbers are based on [Semantic Versioning](https://semver.org/).
# v1.2.1
- Bugfixes
- Fixed CCW faces when using `path_scaling_sections`.
# v1.2
- New modules and functions:
- [starburst](https://openhome.cc/eGossip/OpenSCAD/lib-starburst.html)
- [torus_knot](https://openhome.cc/eGossip/OpenSCAD/lib-torus_knot.html)
- [bijection_offset](https://openhome.cc/eGossip/OpenSCAD/lib-bijection_offset.html)
- [path_scaling_sections](https://openhome.cc/eGossip/OpenSCAD/lib-path_scaling_sections.html)
- Others
- Avoid warnings when using newer versions of OpenSCAD after 2015.03.
# v1.1.1
- Bugfixes
- `m_rotation` returns an identity matrix if `a` is 0.
- The `path_pts` parameter of `path_extrude` accepts two or three points.
- The `points` parameter of `along_with` accepts two or three points.
- Others
- OpenSCAD has built-in matrix multiplication so `m_multiply` is not necessary.
# v1.1
- New matrix functions:
- [m_multiply](https://openhome.cc/eGossip/OpenSCAD/lib-m_multiply.html)

BIN
WhirlingTaiwan.JPG Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 45 KiB

View File

@@ -15,8 +15,8 @@ Creates an arc path. You can pass a 2 element vector to define the central angle
include <hull_polyline2d.scad>;
$fn = 24;
points = arc_path(radius = 20, angle = [45, 290], width = 2);
hull_polyline2d(points);
points = arc_path(radius = 20, angle = [45, 290]);
hull_polyline2d(points, width = 2);
![arc_path](images/lib-arc_path-1.JPG)
@@ -24,8 +24,8 @@ Creates an arc path. You can pass a 2 element vector to define the central angle
include <hull_polyline2d.scad>;
$fn = 24;
points = arc_path(radius = 20, angle = 135, width = 2);
hull_polyline2d(points);
points = arc_path(radius = 20, angle = 135);
hull_polyline2d(points, width = 2);
![arc_path](images/lib-arc_path-2.JPG)

View File

@@ -0,0 +1,67 @@
# bijection_offset
Move 2D outlines outward or inward by a given amount. Each point of the offsetted shape is paired with exactly one point of the original shape.
**Since:** 1.2.
## Parameters
- `pts` : Points of a shape.
- `d` : Amount to offset the shape. When negative, the shape is offset inwards.
## Examples
include <bijection_offset.scad>;
shape = [
[15, 0],
[15, 30],
[0, 20],
[-15, 40],
[-15, 0]
];
color("red") polygon(bijection_offset(shape, 3));
color("orange") polygon(bijection_offset(shape, 2));
color("yellow") polygon(bijection_offset(shape, 1));
color("green") polygon(shape);
color("blue") polygon(bijection_offset(shape, -1));
color("indigo") polygon(bijection_offset(shape, -2));
color("purple") polygon(bijection_offset(shape, -3));
![bijection_offset](images/lib-bijection_offset-1.JPG)
include <bijection_offset.scad>;
include <rotate_p.scad>;
include <polysections.scad>;
include <path_extrude.scad>;
include <bezier_curve.scad>;
shape = [
[5, 0],
[3, 9],
[0, 10],
[-5, 0]
];
offsetted = bijection_offset(shape, 1);
offsetted2 = bijection_offset(shape, 2);
offsetted3 = bijection_offset(shape, 3);
t_step = 0.05;
p0 = [0, 0, 0];
p1 = [40, 60, 35];
p2 = [-50, 70, 0];
p3 = [20, 150, -35];
p4 = [30, 50, -3];
path_pts = bezier_curve(t_step,
[p0, p1, p2, p3, p4]
);
path_extrude(concat(offsetted, shape), path_pts, "HOLLOW");
path_extrude(concat(offsetted3, offsetted2), path_pts, "HOLLOW");
![bijection_offset](images/lib-bijection_offset-2.JPG)

View File

@@ -1,23 +0,0 @@
# 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)

View File

@@ -13,7 +13,7 @@ When using this module, you should use points to represent the 2D shape. If your
- `triangles` : `"SOLID"` (default), `"HOLLOW"` or user-defined indexes. See example below.
- `twist` : The number of degrees of through which the shape is extruded.
- `scale` : Scales the 2D shape by this value over the length of the extrusion. Scale can be a scalar or a vector.
- `closed` : If the first point and the last point of `path_pts` has the same coordinate, setting `closed` to `true` will connect them automatically.
- `closed` : If the first point and the last point of `path_pts` has the same coordinate, setting `closed` to `true` will connect them automatically. You might have to set `twist` for connecting naturally.
## Examples

View File

@@ -0,0 +1,133 @@
# path_scaling_sections
Given an edge path with the first point at the outline of a shape. This function uses the path to calculate scaling factors and returns all scaled sections in the reversed order of the edge path. Combined with the `polysections` module, you can create an extrusion with the path as an edge.
In order to control scaling factors easily, I suggest using `[x, 0, 0]` as the first point and keeping y = 0 while building the edge path.
You can use any point as the first point of the edge path. Just remember that your edge path radiates from the origin.
**Since:** 1.2.
## Parameters
- `shape_pts` : A list of points represent a shape.
- `edge_path` : A list of points represent the edge path.
## Examples
include <hull_polyline3d.scad>;
include <shape_taiwan.scad>;
include <path_scaling_sections.scad>;
include <m_scaling.scad>;
include <polysections.scad>;
taiwan = shape_taiwan(100);
fst_pt = [13, 0, 0];
edge_path = [
fst_pt,
fst_pt + [0, 0, 10],
fst_pt + [10, 0, 20],
fst_pt + [8, 0, 30],
fst_pt + [12, 0, 40],
fst_pt + [0, 0, 50],
fst_pt + [0, 0, 60]
];
#hull_polyline3d(edge_path);
polysections(path_scaling_sections(taiwan, edge_path));
![path_scaling_sections](images/lib-path_scaling_sections-1.JPG)
include <hull_polyline3d.scad>;
include <shape_taiwan.scad>;
include <path_scaling_sections.scad>;
include <m_scaling.scad>;
include <polysections.scad>;
include <bezier_curve.scad>;
taiwan = shape_taiwan(100);
fst_pt = [13, 0, 0];
edge_path = bezier_curve(0.05, [
fst_pt,
fst_pt + [0, 0, 10],
fst_pt + [10, 0, 20],
fst_pt + [8, 0, 30],
fst_pt + [12, 0, 40],
fst_pt + [0, 0, 50],
fst_pt + [0, 0, 60]
]);
#hull_polyline3d(edge_path);
polysections(path_scaling_sections(taiwan, edge_path));
![path_scaling_sections](images/lib-path_scaling_sections-2.JPG)
include <shape_taiwan.scad>;
include <path_scaling_sections.scad>;
include <m_scaling.scad>;
include <polysections.scad>;
include <bezier_curve.scad>;
include <rotate_p.scad>;
taiwan = shape_taiwan(100);
fst_pt = [13, 0, 0];
edge_path = bezier_curve(0.05, [
fst_pt,
fst_pt + [0, 0, 10],
fst_pt + [10, 0, 20],
fst_pt + [8, 0, 30],
fst_pt + [12, 0, 40],
fst_pt + [0, 0, 50],
fst_pt + [0, 0, 60]
]);
leng = len(edge_path);
twist = -90;
twist_step = twist / leng;
sections = path_scaling_sections(taiwan, edge_path);
rotated_sections = [
for(i = [0:leng - 1])
[
for(p = sections[i])
rotate_p(p, twist_step * i)
]
];
polysections(rotated_sections);
![path_scaling_sections](images/lib-path_scaling_sections-3.JPG)
include <hull_polyline3d.scad>;
include <shape_taiwan.scad>;
include <path_scaling_sections.scad>;
include <m_scaling.scad>;
include <polysections.scad>;
include <rotate_p.scad>;
taiwan = shape_taiwan(100);
/*
You can use any point as the first point of the edge path.
Just remember that your edge path radiates from the origin.
*/
fst_pt = [taiwan[0][0], taiwan[0][1], 0];//[13, 0, 0];
a = atan2(fst_pt[1], fst_pt[0]);
edge_path = [
fst_pt,
fst_pt + rotate_p([0, 0, 10], a),
fst_pt + rotate_p([10, 0, 20], a),
fst_pt + rotate_p([8, 0, 30], a),
fst_pt + rotate_p([10, 0, 40], a),
fst_pt + rotate_p([0, 0, 50], a),
fst_pt + rotate_p([0, 0, 60], a)
];
#hull_polyline3d(edge_path);
polysections(path_scaling_sections(taiwan, edge_path));
![path_scaling_sections](images/lib-path_scaling_sections-4.JPG)

View File

@@ -6,6 +6,7 @@ Returns shape points of a regular cyclic polygon. They can be used with xxx_extr
- `sides` : The radius of the circle.
- `circle_r` : The radius of the circumcircle.
- `corner_r` : The radius of the circle at a corner.
- `$fa`, `$fs`, `$fn` : Check [the circle module](https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Using_the_2D_Subsystem#circle) for more details.
## Examples

View File

@@ -6,7 +6,7 @@ Returns shape points of a star. They can be used with xxx_extrude modules of dot
- `r1` : The outer radius of the starburst.
- `r2` : The inner radius of the starburst.
- `n` : The number of vertices.
- `n` : The burst number.
## Examples

24
docs/lib-starburst.md Normal file
View File

@@ -0,0 +1,24 @@
# starburst
A 3D version of `shape_starburst`.
**Since:** 1.2.
## Parameters
- `r1` : The outer radius of the starburst.
- `r2` : The inner radius of the starburst.
- `n` : The number of vertices.
- `height` : The height of the starburst.
## Examples
include <starburst.scad>;
starburst(10, 5, 5, 5);
translate([20, 0, 0]) starburst(10, 5, 6, 5);
translate([40, 0, 0]) starburst(10, 5, 12, 10);
translate([60, 0, 0]) starburst(10, 5, 4, 3);
![starburst](images/lib-starburst-1.JPG)

40
docs/lib-torus_knot.md Normal file
View File

@@ -0,0 +1,40 @@
# torus_knot
Generate a path of [The (p,q)-torus knot](https://en.wikipedia.org/wiki/Torus_knot).
**Since:** 1.2.
![torus_knot](images/lib-torus_knot-1.JPG)
## Parameters
- `p` : The p parameter of The (p,q)-torus knot.
- `q` : The q parameter of The (p,q)-torus knot.
- `phi_step` : The amount when increasing phi.
## Examples
include <shape_pentagram.scad>;
include <rotate_p.scad>;
include <polysections.scad>;
include <path_extrude.scad>;
include <torus_knot.scad>;
p = 2;
q = 3;
phi_step = 0.05;
star_radius = 0.5;
pts = torus_knot(p, q, phi_step);
shape_pentagram_pts = shape_pentagram(star_radius);
path_extrude(
shape_pentagram_pts,
concat(pts, [pts[0]]),
closed = true,
twist = 188
);
![torus_knot](images/lib-torus_knot-2.JPG)

View File

@@ -44,9 +44,9 @@ function __br_corner(frags, b_ang, l1, l2, h, round_r) =
function __half_trapezium(length, h, round_r) =
let(
is_vt = __is_vector(length),
l1 = is_vt ? length[0] : length,
l2 = is_vt ? length[1] : length,
is_flt = __is_float(length),
l1 = is_flt ? length : length[0],
l2 = is_flt ? length : length[1],
frags = __frags(round_r),
b_ang = atan2(h, l1 - l2),
br_corner = __br_corner(frags, b_ang, l1, l2, h, round_r),

View File

@@ -1,13 +0,0 @@
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]
];

View File

@@ -6,7 +6,7 @@ function __shape_arc(radius, angle, width, width_mode = "LINE_CROSS") =
frags = __frags(radius),
a_step = 360 / frags,
half_a_step = a_step / 2,
angles = __is_vector(angle) ? angle : [0, angle],
angles = __is_float(angle) ? [0, angle] : angle,
m = floor(angles[0] / a_step) + 1,
n = floor(angles[1] / a_step),
r_outer = radius + w_offset[0],

View File

@@ -3,7 +3,7 @@ function __shape_pie(radius, angle) =
frags = __frags(radius),
a_step = 360 / frags,
leng = radius * cos(a_step / 2),
angles = __is_vector(angle) ? angle : [0:angle],
angles = __is_float(angle) ? [0:angle] : angle,
m = floor(angles[0] / a_step) + 1,
n = floor(angles[1] / a_step),
edge_r_begin = leng / cos((m - 0.5) * a_step - angles[0]),

View File

@@ -0,0 +1,7 @@
function __to_3_elems_ang_vect(a) =
let(leng = len(a))
leng == 3 ? a : (
leng == 2 ? [a[0], a[1], 0] : [a[0], 0, 0]
);
function __to_ang_vect(a) = __is_float(a) ? [0, 0, a] : __to_3_elems_ang_vect(a);

View File

@@ -7,11 +7,10 @@
* @see https://openhome.cc/eGossip/OpenSCAD/lib-along_with.html
*
**/
include <__private__/__angy_angz.scad>;
include <__private__/__is_vector.scad>;
include <__private__/__is_float.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.
@@ -26,15 +25,23 @@ module along_with(points, angles, twist = 0, scale = 1.0) {
let(s = (scale - 1) / leng_points_minus_one)
[s, s, s];
scale_step_vt = __is_vector(scale) ?
scale_step_vt = __is_float(scale) ?
scale_step() :
[
(scale[0] - 1) / leng_points_minus_one,
(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
identity_matrix = [
[1, 0, 0, 0],
[0, 1, 0, 0],
[0, 0, 1, 0],
[0, 0, 0, 1]
];
function local_ang_vects(j) =
j == 0 ? [] : local_ang_vects_sub(j);
@@ -53,12 +60,16 @@ module along_with(points, angles, twist = 0, scale = 1.0) {
leng_rot_matrice_minus_one = leng_rot_matrice - 1,
leng_rot_matrice_minus_two = leng_rot_matrice - 2
)
i == leng_rot_matrice - 2 ?
leng_rot_matrice == 0 ? [identity_matrix] : (
leng_rot_matrice == 1 ? [rot_matrice[0], identity_matrix] : (
i == leng_rot_matrice_minus_two ?
[
rot_matrice[leng_rot_matrice_minus_one],
__m_multiply(rot_matrice[leng_rot_matrice_minus_two], rot_matrice[leng_rot_matrice_minus_one])
rot_matrice[leng_rot_matrice_minus_two] * rot_matrice[leng_rot_matrice_minus_one]
]
: cumulated_rot_matrice_sub(i, rot_matrice);
: cumulated_rot_matrice_sub(i, rot_matrice)
)
);
function cumulated_rot_matrice_sub(i, rot_matrice) =
let(
@@ -66,7 +77,7 @@ module along_with(points, angles, twist = 0, scale = 1.0) {
curr_matrix = rot_matrice[i],
prev_matrix = matrice[len(matrice) - 1]
)
concat(matrice, [__m_multiply(curr_matrix, prev_matrix)]);
concat(matrice, [curr_matrix * prev_matrix]);
// align modules

View File

@@ -9,7 +9,7 @@
**/
include <__private__/__frags.scad>;
include <__private__/__is_vector.scad>;
include <__private__/__is_float.scad>;
include <__private__/__ra_to_xy.scad>;
include <__private__/__edge_r.scad>;
include <__private__/__shape_arc.scad>;

View File

@@ -9,7 +9,7 @@
**/
include <__private__/__frags.scad>;
include <__private__/__is_vector.scad>;
include <__private__/__is_float.scad>;
include <__private__/__ra_to_xy.scad>;
include <__private__/__edge_r.scad>;
@@ -17,7 +17,7 @@ function arc_path(radius, angle) =
let(
frags = __frags(radius),
a_step = 360 / frags,
angles = __is_vector(angle) ? angle : [0, angle],
angles = __is_float(angle) ? [0, angle] : angle,
m = floor(angles[0] / a_step) + 1,
n = floor(angles[1] / a_step),
points = concat([__ra_to_xy(__edge_r_begin(radius, angles[0], a_step, m), angles[0])],

86
src/bijection_offset.scad Normal file
View File

@@ -0,0 +1,86 @@
/**
* bijection_offset.scad
*
* @copyright Justin Lin, 2019
* @license https://opensource.org/licenses/lgpl-3.0.html
*
* @see https://openhome.cc/eGossip/OpenSCAD/lib-bijection_offset.html
*
**/
function _bijection_edges_from(pts) =
let(leng = len(pts))
concat(
[for(i = [0:leng - 2]) [pts[i], pts[i + 1]]],
[[pts[len(pts) - 1], pts[0]]]
);
function _bijection_inward_edge_normal(edge) =
let(
pt1 = edge[0],
pt2 = edge[1],
dx = pt2[0] - pt1[0],
dy = pt2[1] - pt1[1],
edge_leng = norm([dx, dy])
)
[-dy / edge_leng, dx / edge_leng];
function _bijection_outward_edge_normal(edge) = -1 * _bijection_inward_edge_normal(edge);
function _bijection_offset_edge(edge, dx, dy) =
let(
pt1 = edge[0],
pt2 = edge[1],
dxy = [dx, dy]
)
[pt1 + dxy, pt2 + dxy];
function _bijection__bijection_offset_edges(edges, d) =
[
for(edge = edges)
let(
ow_normal = _bijection_outward_edge_normal(edge),
dx = ow_normal[0] * d,
dy = ow_normal[1] * d
)
_bijection_offset_edge(edge, dx, dy)
];
function _bijection__bijection__bijection_offset_edges_intersection(edge1, edge2) =
let(
den = (edge2[1][1] - edge2[0][1]) * (edge1[1][0] - edge1[0][0]) - (edge2[1][0] - edge2[0][0]) * (edge1[1][1] - edge1[0][1])
)
// when den is 0, they are parallel or conincident edges
den == 0 ? [] : _bijection_offset__bijection__bijection__bijection_offset_edges_intersection_sub(edge1, edge2, den);
function _bijection_offset__bijection__bijection__bijection_offset_edges_intersection_sub(edge1, edge2, den) =
let(
ua = ((edge2[1][0] - edge2[0][0]) * (edge1[0][1] - edge2[0][1]) - (edge2[1][1] - edge2[0][1]) * (edge1[0][0] - edge2[0][0])) / den
)
[
edge1[0][0] + ua * (edge1[1][0] - edge1[0][0]),
edge1[0][1] + ua * (edge1[1][1] - edge1[0][1])
];
function bijection_offset(pts, d) =
let(
es = _bijection_edges_from(pts),
offset_es = _bijection__bijection_offset_edges(es, d),
leng = len(offset_es),
last_p = _bijection__bijection__bijection_offset_edges_intersection(offset_es[leng - 1], offset_es[0])
)
concat(
[
for(i = [0:leng - 2])
let(
this_edge = offset_es[i],
next_edge = offset_es[i + 1],
p = _bijection__bijection__bijection_offset_edges_intersection(this_edge, next_edge)
)
// p == p to avoid [nan, nan], because [nan, nan] != [nan, nan]
if(p != [] && p == p) p
],
last_p != [] && last_p == last_p ? [last_p] : []
);

View File

@@ -9,16 +9,17 @@
**/
include <__private__/__to3d.scad>;
include <__private__/__is_vector.scad>;
include <__private__/__is_float.scad>;
function cross_sections(shape_pts, path_pts, angles, twist = 0, scale = 1.0) =
let(
len_path_pts_minus_one = len(path_pts) - 1,
sh_pts = len(shape_pts[0]) == 3 ? shape_pts : [for(p = shape_pts) __to3d(p)],
pth_pts = len(path_pts[0]) == 3 ? path_pts : [for(p = path_pts) __to3d(p)],
scale_step_vt = __is_vector(scale) ?
[(scale[0] - 1) / len_path_pts_minus_one, (scale[1] - 1) / len_path_pts_minus_one] :
[(scale - 1) / len_path_pts_minus_one, (scale - 1) / len_path_pts_minus_one],
scale_step_vt = __is_float(scale) ?
[(scale - 1) / len_path_pts_minus_one, (scale - 1) / len_path_pts_minus_one] :
[(scale[0] - 1) / len_path_pts_minus_one, (scale[1] - 1) / len_path_pts_minus_one]
,
scale_step_x = scale_step_vt[0],
scale_step_y = scale_step_vt[1],
twist_step = twist / len_path_pts_minus_one

View File

@@ -9,10 +9,10 @@
**/
include <__private__/__nearest_multiple_of_4.scad>;
include <__private__/__is_vector.scad>;
include <__private__/__is_float.scad>;
module crystal_ball(radius, theta = 360, phi = 180) {
phis = __is_vector(phi) ? phi : [0, phi];
phis = __is_float(phi) ? [0, phi] : phi;
frags = __frags(radius);

View File

@@ -8,14 +8,14 @@
*
**/
include <__private__/__is_vector.scad>;
include <__private__/__is_float.scad>;
include <__private__/__frags.scad>;
function helix(radius, levels, level_dist, vt_dir = "SPI_DOWN", rt_dir = "CT_CLK") =
let(
is_vt = __is_vector(radius),
r1 = is_vt ? radius[0] : radius,
r2 = is_vt ? radius[1] : radius,
is_flt = __is_float(radius),
r1 = is_flt ? radius : radius[0],
r2 = is_flt ? radius : radius[1],
init_r = vt_dir == "SPI_DOWN" ? r2 : r1,
_frags = __frags(init_r),
h = level_dist * levels,

View File

@@ -8,7 +8,7 @@
*
**/
include <__private__/__is_vector.scad>;
include <__private__/__is_float.scad>;
include <__private__/__frags.scad>;
module helix_extrude(shape_pts, radius, levels, level_dist,
@@ -22,9 +22,9 @@ module helix_extrude(shape_pts, radius, levels, level_dist,
vt[leng - 1 - i]
];
is_vt = __is_vector(radius);
r1 = is_vt ? radius[0] : radius;
r2 = is_vt ? radius[1] : radius;
is_flt = __is_float(radius);
r1 = is_flt ? radius : radius[0];
r2 = is_flt ? radius : radius[1];
init_r = vt_dir == "SPI_DOWN" ? r2 : r1;

View File

@@ -8,12 +8,10 @@
*
**/
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));
matrice[i] * matrice[i + 1] :
matrice[i] * _m_cumulate(matrice, i + 1);
function m_cumulate(matrice) =
len(matrice) == 1 ? matrice[0] : _m_cumulate(matrice, 0);

View File

@@ -1,13 +0,0 @@
/**
* 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);

View File

@@ -8,7 +8,8 @@
*
**/
include <__private__/__m_multiply.scad>;
include <__private__/__is_float.scad>;
include <__private__/__to_ang_vect.scad>;
function _q_rotation(a, v) =
let(
@@ -68,20 +69,14 @@ function _m_zRotation(a) =
[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])
)
);
let(ang = __to_ang_vect(a))
_m_zRotation(ang[2]) * _m_yRotation(ang[1]) * _m_xRotation(ang[0]);
function m_rotation(a, v) =
v == undef ? _xyz_rotation(a) : _q_rotation(a, v);
(a == 0 || a == [0, 0, 0] || a == [0] || a == [0, 0]) ? [
[1, 0, 0, 0],
[0, 1, 0, 0],
[0, 0, 1, 0],
[0, 0, 0, 1]
] : (v == undef ? _xyz_rotation(a) : _q_rotation(a, v));

View File

@@ -8,15 +8,18 @@
*
**/
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]
)
include <__private__/__is_float.scad>;
function _to_3_elems_scaling_vect(s) =
let(leng = len(s))
leng == 3 ? s : (
leng == 2 ? [s[0], s[1], 1] : [s[0], 1, 1]
);
function _to_scaling_vect(s) = __is_float(s) ? [s, s, s] : _to_3_elems_scaling_vect(s);
function m_scaling(s) =
let(v = _to_svect(s))
let(v = _to_scaling_vect(s))
[
[v[0], 0, 0, 0],
[0, v[1], 0, 0],

View File

@@ -8,7 +8,6 @@
*
**/
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);

View File

@@ -8,15 +8,18 @@
*
**/
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]
)
include <__private__/__is_float.scad>;
function _to_3_elems_translation_vect(v) =
let(leng = len(v))
leng == 3 ? v : (
leng == 2 ? [v[0], v[1], 0] : [v[0], 0, 0]
);
function _to_translation_vect(v) = __is_float(v) ? [v, 0, 0] : _to_3_elems_translation_vect(v);
function m_translation(v) =
let(vt = _to_tvect(v))
let(vt = _to_translation_vect(v))
[
[1, 0, 0, vt[0]],
[0, 1, 0, vt[1]],

View File

@@ -8,10 +8,9 @@
*
**/
include <__private__/__is_vector.scad>;
include <__private__/__is_float.scad>;
include <__private__/__to3d.scad>;
include <__private__/__angy_angz.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.
@@ -40,12 +39,13 @@ module path_extrude(shape_pts, path_pts, triangles = "SOLID", twist = 0, scale =
let(s = (scale - 1) / len_path_pts_minus_one)
[s, s, s];
scale_step_vt = __is_vector(scale) ?
scale_step_vt = __is_float(scale) ?
scale_step() :
[
(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();
];
// get rotation matrice for sections
@@ -70,13 +70,24 @@ module path_extrude(shape_pts, path_pts, triangles = "SOLID", twist = 0, scale =
leng_rot_matrice_minus_one = leng_rot_matrice - 1;
leng_rot_matrice_minus_two= leng_rot_matrice - 2;
identity_matrix = [
[1, 0, 0, 0],
[0, 1, 0, 0],
[0, 0, 1, 0],
[0, 0, 0, 1]
];
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);
leng_rot_matrice == 0 ? [identity_matrix] : (
leng_rot_matrice == 1 ? [rot_matrice[0], identity_matrix] :
(
i == leng_rot_matrice_minus_two ?
[
rot_matrice[leng_rot_matrice_minus_one],
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(
@@ -84,7 +95,7 @@ module path_extrude(shape_pts, path_pts, triangles = "SOLID", twist = 0, scale =
curr_matrix = rot_matrice[i],
prev_matrix = matrice[len(matrice) - 1]
)
concat(matrice, [__m_multiply(curr_matrix, prev_matrix)]);
concat(matrice, [curr_matrix * prev_matrix]);
cumu_rot_matrice = cumulated_rot_matrice(0);

View File

@@ -0,0 +1,30 @@
/**
* path_scaling_sections.scad
*
* @copyright Justin Lin, 2019
* @license https://opensource.org/licenses/lgpl-3.0.html
*
* @see https://openhome.cc/eGossip/OpenSCAD/lib-path_scaling_sections.html
*
**/
include <__private__/__reverse.scad>;
function path_scaling_sections(shape_pts, edge_path) =
let(
start_point = edge_path[0],
base_leng = norm(start_point),
scaling_matrice = [
for(p = edge_path)
let(s = norm([p[0], p[1], 0]) / base_leng)
m_scaling([s, s, 1])
]
)
__reverse([
for(i = [0:len(edge_path) - 1])
[
for(p = shape_pts)
let(scaled_p = scaling_matrice[i] * [p[0], p[1], edge_path[i][2], 1])
[scaled_p[0], scaled_p[1], scaled_p[2]]
]
]);

View File

@@ -9,7 +9,7 @@
**/
include <__private__/__frags.scad>;
include <__private__/__is_vector.scad>;
include <__private__/__is_float.scad>;
include <__private__/__ra_to_xy.scad>;
include <__private__/__shape_pie.scad>;

View File

@@ -19,7 +19,7 @@ module ring_extrude(shape_pts, radius, angle = 360, twist = 0, scale = 1.0, tria
} else {
a_step = 360 / __frags(radius);
angles = __is_vector(angle) ? angle : [0, angle];
angles = __is_float(angle) ? [0, angle] : angle;
m = floor(angles[0] / a_step) + 1;
n = floor(angles[1] / a_step);

View File

@@ -10,7 +10,8 @@
include <__private__/__to2d.scad>;
include <__private__/__to3d.scad>;
include <__private__/__is_float.scad>;
include <__private__/__to_ang_vect.scad>;
function _q_rotate_p_3d(p, a, v) =
let(
@@ -69,15 +70,8 @@ function _rotz(pt, a) =
function _rotate_p_3d(point, a) =
_rotz(_roty(_rotx(point, a[0]), a[1]), a[2]);
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 _rotate_p(p, a) =
let(angle = _to_avect(a))
let(angle = __to_ang_vect(a))
len(p) == 3 ?
_rotate_p_3d(p, angle) :
__to2d(

View File

@@ -8,15 +8,15 @@
*
**/
include <__private__/__is_vector.scad>;
include <__private__/__is_float.scad>;
include <__private__/__frags.scad>;
include <__private__/__nearest_multiple_of_4.scad>;
module rounded_cube(size, corner_r, center = false) {
is_vt = __is_vector(size);
x = is_vt ? size[0] : size;
y = is_vt ? size[1] : size;
z = is_vt ? size[2] : size;
is_flt = __is_float(size);
x = is_flt ? size : size[0];
y = is_flt ? size : size[1];
z = is_flt ? size : size[2];
corner_frags = __nearest_multiple_of_4(__frags(corner_r));
edge_d = corner_r * cos(180 / corner_frags);

View File

@@ -8,7 +8,7 @@
*
**/
include <__private__/__is_vector.scad>;
include <__private__/__is_float.scad>;
include <__private__/__frags.scad>;
include <__private__/__pie_for_rounding.scad>;
include <__private__/__half_trapezium.scad>;

View File

@@ -9,13 +9,13 @@
**/
include <__private__/__frags.scad>;
include <__private__/__is_vector.scad>;
include <__private__/__is_float.scad>;
module rounded_extrude(size, round_r, angle = 90, twist = 0, convexity = 10) {
is_vt = __is_vector(size);
x = is_vt ? size[0] : size;
y = is_vt ? size[1] : size;
is_flt = __is_float(size);
x = is_flt ? size : size[0];
y = is_flt ? size : size[1];
q_corner_frags = __frags(round_r) / 4;

View File

@@ -8,16 +8,16 @@
*
**/
include <__private__/__is_vector.scad>;
include <__private__/__is_float.scad>;
include <__private__/__frags.scad>;
include <__private__/__pie_for_rounding.scad>;
include <__private__/__half_trapezium.scad>;
include <__private__/__trapezium.scad>;
module rounded_square(size, corner_r, center = false) {
is_vt = __is_vector(size);
x = is_vt ? size[0] : size;
y = is_vt ? size[1] : size;
is_flt = __is_float(size);
x = is_flt ? size : size[0];
y = is_flt ? size : size[1];
position = center ? [0, 0] : [x / 2, y / 2];
points = __trapezium(

View File

@@ -9,9 +9,10 @@
**/
include <__private__/__frags.scad>;
include <__private__/__is_vector.scad>;
include <__private__/__is_float.scad>;
include <__private__/__ra_to_xy.scad>;
include <__private__/__shape_arc.scad>;
include <__private__/__edge_r.scad>
function shape_arc(radius, angle, width, width_mode = "LINE_CROSS") =
__shape_arc(radius, angle, width, width_mode);

View File

@@ -9,7 +9,7 @@
**/
include <__private__/__frags.scad>;
include <__private__/__is_vector.scad>;
include <__private__/__is_float.scad>;
include <__private__/__ra_to_xy.scad>;
include <__private__/__shape_pie.scad>;

View File

@@ -8,17 +8,17 @@
*
**/
include <__private__/__is_vector.scad>;
include <__private__/__is_float.scad>;
include <__private__/__frags.scad>;
include <__private__/__pie_for_rounding.scad>;
include <__private__/__half_trapezium.scad>;
include <__private__/__trapezium.scad>;
function shape_square(size, corner_r = 0) =
let(
is_vt = __is_vector(size),
x = is_vt ? size[0] : size,
y = is_vt ? size[1] : size
is_flt = __is_float(size),
x = is_flt ? size : size[0],
y = is_flt ? size : size[1]
)
__trapezium(
length = x,

File diff suppressed because one or more lines are too long

View File

@@ -8,7 +8,7 @@
*
**/
include <__private__/__is_vector.scad>;
include <__private__/__is_float.scad>;
include <__private__/__frags.scad>;
include <__private__/__pie_for_rounding.scad>;
include <__private__/__half_trapezium.scad>;

View File

@@ -8,7 +8,6 @@
*
**/
include <__private__/__m_multiply.scad>;
include <__private__/__m_shearing.scad>;
module shear(sx = [0, 0], sy = [0, 0], sz = [0, 0]) {

42
src/starburst.scad Normal file
View File

@@ -0,0 +1,42 @@
/**
* starburst.scad
*
* @copyright Justin Lin, 2019
* @license https://opensource.org/licenses/lgpl-3.0.html
*
* @see https://openhome.cc/eGossip/OpenSCAD/lib-starburst.html
*
**/
module starburst(r1, r2, n, height) {
a = 180 / n;
p0 = [0, 0, 0];
p1 = [r2 * cos(a), r2 * sin(a), 0];
p2 = [r1, 0, 0];
p3 = [0, 0, height];
module half_burst() {
polyhedron(points = [p0, p1, p2, p3],
faces = [
[0, 2, 1],
[0, 1, 3],
[0, 3, 2],
[2, 1, 3]
]
);
}
module burst() {
hull() {
half_burst();
mirror([0, 1,0]) half_burst();
}
}
union() {
for(i = [0 : n - 1]) {
rotate(2 * a * i) burst();
}
}
}

21
src/torus_knot.scad Normal file
View File

@@ -0,0 +1,21 @@
/**
* torus_knot.scad
*
* @copyright Justin Lin, 2019
* @license https://opensource.org/licenses/lgpl-3.0.html
*
* @see https://openhome.cc/eGossip/OpenSCAD/lib-torus_knot.html
*
**/
function torus_knot(p, q, phi_step) = [
for(phi = [0:phi_step:6.28318])
let(
degree = phi * 180 / 3.14159,
r = cos(q * degree) + 2,
x = r * cos(p * degree),
y = r * sin(p * degree),
z = -sin(q * degree)
)
[x, y, z]
];

View File

@@ -14,8 +14,6 @@ module test_hull_polyline2d() {
assertEqualPoint(points[index], point2);
assertEqual(line_width, radius * 2);
}
$fn = 4;
hull_polyline2d(
points = [[1, 2], [-5, -4], [-5, 3], [5, 5]],

File diff suppressed because one or more lines are too long