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

update doc

This commit is contained in:
Justin Lin
2022-04-06 17:44:11 +08:00
parent adf07c5da8
commit d0474ed757
48 changed files with 253 additions and 236 deletions

View File

@@ -16,7 +16,8 @@ Creates an arc path. You can pass a 2 element vector to define the central angle
$fn = 24;
points = arc_path(radius = 20, angle = [45, 290]);
polyline_join(points) circle(1);
polyline_join(points)
circle(1);
![arc_path](images/lib3x-arc_path-1.JPG)
@@ -25,7 +26,8 @@ Creates an arc path. You can pass a 2 element vector to define the central angle
$fn = 24;
points = arc_path(radius = 20, angle = 135);
polyline_join(points) circle(1);
polyline_join(points)
circle(1);
![arc_path](images/lib3x-arc_path-2.JPG)

View File

@@ -26,7 +26,8 @@ Creates visually even spacing of n points on the surface of the sphere. Successi
sphere(1, $fn = 24);
}
polyline_join(pts) sphere(.5);
polyline_join(pts)
sphere(.5);
![bauer_spiral](images/lib3x-bauer_spiral-1.JPG)

View File

@@ -51,6 +51,7 @@ Given a path, the `bezier_smooth` function uses bazier curves to smooth all corn
smoothed_path_pts = bezier_smooth(path_pts, round_d, closed = true);
translate([50, 0, 0]) polygon(smoothed_path_pts);
translate([50, 0, 0])
polygon(smoothed_path_pts);
![bezier_smooth](images/lib3x-bezier_smooth-2.JPG)

View File

@@ -43,7 +43,6 @@ Move 2D outlines outward or inward by a given amount. Each point of the offsette
[-5, 0]
];
offsetted = bijection_offset(shape, 1);
offsetted2 = bijection_offset(shape, 2);
offsetted3 = bijection_offset(shape, 3);

View File

@@ -49,7 +49,8 @@
// a non-uniform B-spline curve
knots = [0, 1/8, 1/4, 1/2, 3/4, 4/5, 1];
color("red") for(p = points) {
color("red")
for(p = points) {
translate(p)
sphere(0.5);
}
@@ -73,7 +74,8 @@
// For a clamped B-spline curve, the first `degree + 1` and the last `degree + 1` knots must be identical.
knots = [0, 0, 0, 1, 2, 2, 2];
color("red") for(p = points) {
color("red")
for(p = points) {
translate(p)
sphere(0.5);
}

View File

@@ -16,26 +16,21 @@ returns a new list with all sub-list elements concatenated into it recursively u
vt = [[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]];
assert(
flat([1, 2, [3, 4]]) ==
[1, 2, 3, 4]
flat([1, 2, [3, 4]]) == [1, 2, 3, 4]
);
assert(
flat([[1, 2], [3, 4]]) ==
[1, 2, 3, 4]
flat([[1, 2], [3, 4]]) == [1, 2, 3, 4]
);
assert(
flat([[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]]) ==
[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]
flat([[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]]) == [[[1, 2], [3, 4]], [[5, 6], [7, 8]]]
);
assert(
flat([[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]], 2) ==
[[1, 2], [3, 4], [5, 6], [7, 8]]
flat([[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]], 2) == [[1, 2], [3, 4], [5, 6], [7, 8]]
);
assert(
flat([[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]], 3) ==
[1, 2, 3, 4, 5, 6, 7, 8]
flat([[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]], 3) == [1, 2, 3, 4, 5, 6, 7, 8]
);

View File

@@ -39,9 +39,9 @@ This function maps keys to values. You can use the following to process the retu
m3 = hashmap_del(m2, "k1");
assert(hashmap_get(m3, "k1") == undef);
echo(hashmap_keys(m3)); // a list contains "k2", "k2", "k3"
echo(hashmap_values(m3)); // a list contains 20, 30, 40
echo(hashmap_entries(m3)); // a list contains ["k2", 20], ["k3", 30], ["k4", 40]
assert(hashmap_keys(m3) == ["k2", "k3", "k4"]);
assert(hashmap_values(m3) == [20, 30, 40]);
assert(hashmap_entries(m3) == [["k2", 20], ["k3", 30], ["k4", 40]]);
Want to simulate class-based OO in OpenSCAD? Here's my experiment.

View File

@@ -35,4 +35,4 @@ This function models the mathematical set, backed by a hash table. You can use t
s3 = hashset_del(s2, 2);
assert(!hashset_has(s3, 2));
echo(hashset_elems(s3)); // a list contains 1, 3, 4, 5, 9
assert(hashset_elems(s3) == [1, 3, 4, 5, 9]);

View File

@@ -14,5 +14,5 @@ Returns a list containing all elements in a [util/set/hashset](https://openhome.
use <util/set/hashset_elems.scad>;
s = hashset([1, 2, 3, 4, 5]);
echo(hashset_elems(s)); // a list contains 1, 2, 3, 4, 5
assert(hashset_elems(s) == [1, 2, 3, 4, 5]);

View File

@@ -27,7 +27,8 @@ Gets all points on the path of a spiral around a cylinder. Its `$fa`, `$fs` and
);
for(p = points) {
translate(p) sphere(5);
translate(p)
sphere(5);
}
polyline_join(points)

View File

@@ -10,7 +10,10 @@ Hollows out a 2D object.
use <hollow_out.scad>;
hollow_out(shell_thickness = 1) circle(r = 3, $fn = 48);
hollow_out(shell_thickness = 1) square([10, 5]);
hollow_out(shell_thickness = 1)
circle(r = 3, $fn = 48);
hollow_out(shell_thickness = 1)
square([10, 5]);
![hollow_out](images/lib3x-hollow_out-1.JPG)

View File

@@ -20,10 +20,10 @@ Checks whether a point is on a line.
[10, 10]
];
echo(in_polyline(pts, [-2, -3])); // false
echo(in_polyline(pts, [5, 0])); // true
echo(in_polyline(pts, [10, 5])); // true
echo(in_polyline(pts, [10, 15])); // false
assert(!in_polyline(pts, [-2, -3]));
assert(in_polyline(pts, [5, 0]));
assert(in_polyline(pts, [10, 5]));
assert(!in_polyline(pts, [10, 15]));
----
@@ -35,7 +35,7 @@ Checks whether a point is on a line.
[20, 10, 10]
];
echo(in_polyline(pts, [10, 0, 10])); // true
echo(in_polyline(pts, [15, 0, 10])); // true
echo(in_polyline(pts, [15, 1, 10])); // false
echo(in_polyline(pts, [20, 11, 10])); // false
assert(in_polyline(pts, [10, 0, 10]));
assert(in_polyline(pts, [15, 0, 10]));
assert(!in_polyline(pts, [15, 1, 10]));
assert(!in_polyline(pts, [20, 11, 10]));

View File

@@ -18,10 +18,12 @@ Generate a 4x4 transformation matrix which can pass into `multmatrix` to shear a
multmatrix(m_shearing(sx = [1, 0]))
cube(1);
translate([2, 0, 0]) multmatrix(m_shearing(sx = [0, 1]))
translate([2, 0, 0])
multmatrix(m_shearing(sx = [0, 1]))
cube(1);
translate([4, 0, 0]) multmatrix(m_shearing(sx = [1, 1]))
translate([4, 0, 0])
multmatrix(m_shearing(sx = [1, 1]))
cube(1);
}
@@ -29,10 +31,12 @@ Generate a 4x4 transformation matrix which can pass into `multmatrix` to shear a
multmatrix(m_shearing(sy = [1, 0]))
cube(1);
translate([2, 0, 0]) multmatrix(m_shearing(sy = [0, 1]))
translate([2, 0, 0])
multmatrix(m_shearing(sy = [0, 1]))
cube(1);
translate([4, 0, 0]) multmatrix(m_shearing(sy = [1, 1]))
translate([4, 0, 0])
multmatrix(m_shearing(sy = [1, 1]))
cube(1);
}
@@ -40,10 +44,12 @@ Generate a 4x4 transformation matrix which can pass into `multmatrix` to shear a
multmatrix(m_shearing(sz = [1, 0]))
cube(1);
translate([2, 0, 0]) multmatrix(m_shearing(sz = [0, 1]))
translate([2, 0, 0])
multmatrix(m_shearing(sz = [0, 1]))
cube(1);
translate([4, 0, 0]) multmatrix(m_shearing(sz = [1, 1]))
translate([4, 0, 0])
multmatrix(m_shearing(sz = [1, 1]))
cube(1);
}

View File

@@ -19,7 +19,12 @@ Given a 2D path, this function constructs a mid-point smoothed version by joinin
taiwan = shape_taiwan(50);
smoothed = midpt_smooth(taiwan, 20, true);
translate([0, 0, 0]) polyline_join(taiwan) circle(.125);
#translate([10, 0, 0]) polyline_join(smoothed) circle(.125);
translate([0, 0, 0])
polyline_join(taiwan)
circle(.125);
#translate([10, 0, 0])
polyline_join(smoothed)
circle(.125);
![midpt_smooth](images/lib3x-midpt_smooth-1.JPG)

View File

@@ -41,11 +41,9 @@ The cell data is seperated from views. You can use cell data to construct [diffe
cells = mz_square_cells(rows, columns);
for(cell = cells) {
x = cell[0];
y = cell[1];
type = cell[2];
translate([x, y] * cell_width) {
translate([cell.x, cell.y] * cell_width) {
if(type == TOP_WALL || type == TOP_RIGHT_WALL) {
line2d([0, cell_width], [cell_width, cell_width], wall_thickness);
}

View File

@@ -68,14 +68,12 @@ It's a helper for initializing cell data of a maze.
// Mask
mask_width = cell_width + wall_thickness;
translate([-wall_thickness / 2, -wall_thickness / 2])
for(i = [0:rows - 1]) {
for(j = [0:columns - 1]) {
for(i = [0:rows - 1], j = [0:columns - 1]) {
if(mask[i][j] == 0) {
translate([cell_width * j, cell_width * (rows - i - 1)])
square(mask_width);
}
}
}
![mz_square_initialize](images/lib3x-mz_square_initialize-2.JPG)

View File

@@ -42,8 +42,7 @@ The value of `type` is the wall type of the cell. It can be `0`, `1`, `2` or `3`
maze = mz_theta_cells(rows, beginning_number);
// draw cell walls
for(rows = maze) {
for(cell = rows) {
for(rows = maze, cell = rows) {
ri = cell[0];
ci = cell[1];
type = cell[2];
@@ -67,7 +66,6 @@ The value of `type` is the wall type of the cell. It can be `0`, `1`, `2` or `3`
circle(wall_thickness / 2);
}
}
}
// outmost walls
thetaStep = 360 / len(maze[rows - 1]);

View File

@@ -23,8 +23,7 @@ It's a helper for getting data from a theta-maze cell.
function vt_from_angle(theta, r) = [r * cos(theta), r * sin(theta)];
maze = mz_theta_cells(rows, beginning_number);
for(rows = maze) {
for(cell = rows) {
for(rows = maze, cell = rows) {
ri = mz_theta_get(cell, "r");
ci = mz_theta_get(cell, "c");
type = mz_theta_get(cell, "t");
@@ -48,7 +47,6 @@ It's a helper for getting data from a theta-maze cell.
circle(wall_thickness / 2);
}
}
}
thetaStep = 360 / len(maze[rows - 1]);
r = cell_width * (rows + 1);

View File

@@ -26,8 +26,7 @@ It's an implementation of [Worley noise](https://en.wikipedia.org/wiki/Worley_no
feature_points = [for(pt_angle = pts_angles) pt_angle[0] + half_size];
noised = [
for(y = [0:size.y - 1])
for(x = [0:size.x - 1])
for(y = [0:size.y - 1], x = [0:size.x - 1])
[x, y, nz_cell(feature_points, [x, y])]
];

View File

@@ -18,15 +18,13 @@ Returns the 3D [Perlin noise](https://en.wikipedia.org/wiki/Perlin_noise) value
seed = rand(0, 255);
noised = [
for(z = [0:.2:5])
for(y = [0:.2:5])
for(x = [0:.2:5])
for(z = [0:.2:5], y = [0:.2:5], x = [0:.2:5])
[x, y, z, nz_perlin3(x, y, z, seed)]
];
for(nz = noised) {
if(nz[3] > 0.2) {
translate([nz[0], nz[1], nz[2]])
translate([nz.x, nz.y, nz.z])
cube(.2);
}
}

View File

@@ -39,7 +39,7 @@ Returns 3D [Perlin noise](https://en.wikipedia.org/wiki/Perlin_noise) values at
for(i = [0:len(row) - 1]) {
p = row[i];
pts = [
for(z = [0:.2:p[2] * h_scale]) [p[0], p[1], z]
for(z = [0:.2:p[2] * h_scale]) [p.x, p.y, z]
];
noise = nz_perlin3s(pts, seed);
for(j = [0:len(pts) - 1]) {

View File

@@ -27,8 +27,7 @@ It divides the space into grids. The nucleus of each cell is randomly placed in
seed = 51;
points = [
for(y = [0:size.y - 1])
for(x = [0:size.x - 1])
for(y = [0:size.y - 1], x = [0:size.x - 1])
[x, y]
];
@@ -43,7 +42,7 @@ It divides the space into grids. The nucleus of each cell is randomly placed in
square(1);
}
cells_pts = dedup([for(c = cells) [c[0], c[1]]]);
cells_pts = dedup([for(c = cells) [c.x, c.y]]);
for(p = cells_pts) {
translate(p)
linear_extrude(max_dist)

View File

@@ -25,8 +25,7 @@ It divides the space into grids. The nucleus of each cell is randomly placed in
seed = 51;
points = [
for(y = [0:size.y - 1])
for(x = [0:size.x - 1])
for(y = [0:size.y - 1], x = [0:size.x - 1])
[x, y]
];

View File

@@ -26,7 +26,7 @@ It divides the space into grids. The nucleus of each cell is randomly placed in
cells = nz_worley3s(points, seed, grid_w, dist);
for(i = [0:len(cells) - 1]) {
c = (norm([cells[i][0], cells[i][1], cells[i][2]]) % 20) / 20;
c = (norm([cells[i].x, cells[i].y, cells[i].z]) % 20) / 20;
color([c, c, c])
translate(points[i])
cube(1);

View File

@@ -255,7 +255,8 @@ So, which is the correct method? Both methods are correct when you provide only
shape_pentagram_pts = shape_pentagram(star_radius);
// not closed perfectly
translate([-8, 0, 0]) path_extrude(
translate([-8, 0, 0])
path_extrude(
shape_pentagram_pts,
[each pts, pts[0]],
closed = true,
@@ -272,7 +273,8 @@ So, which is the correct method? Both methods are correct when you provide only
);
// "EULER_ANGLE" is easy in this situation
translate([0, 8, 0]) path_extrude(
translate([0, 8, 0])
path_extrude(
shape_pentagram_pts,
[each pts, pts[0]],
closed = true,

View File

@@ -45,7 +45,6 @@ You can use any point as the first point of the edge path. Just remember that yo
use <sweep.scad>;
use <bezier_curve.scad>;
taiwan = shape_taiwan(100);
fst_pt = [13, 0, 0];

View File

@@ -13,8 +13,10 @@ Creates a pie (circular sector). Its `$fa`, `$fs` and `$fn` are consistent with
use <pie.scad>;
pie(radius = 20, angle = [210, 310]);
translate([-15, 0, 0]) pie(radius = 20, angle = [45, 135]);
translate([15, 0, 0]) pie(radius = 20, angle = [45, 135], $fn = 12);
translate([-15, 0, 0])
pie(radius = 20, angle = [45, 135]);
translate([15, 0, 0])
pie(radius = 20, angle = [45, 135], $fn = 12);
![pie](images/lib3x-pie-1.JPG)

View File

@@ -17,8 +17,7 @@ Creates a [superellipsoid](https://en.wikipedia.org/wiki/Superellipsoid).
step = 0.5;
for(e = [0:step:4]) {
for(n = [0:step:4])
for(e = [0:step:4], n = [0:step:4]) {
translate([e / step, n / step] * 3)
superellipsoid(e, n);
}

View File

@@ -23,16 +23,23 @@ Creates a polyline from a list of `[x, y]` coordinates. When the end points are
use <polyline2d.scad>;
$fn = 24;
polyline2d(points = [[1, 2], [-5, -4], [-5, 3], [5, 5]], width = 1,
endingStyle = "CAP_ROUND");
polyline2d(
points = [[1, 2], [-5, -4], [-5, 3], [5, 5]],
width = 1,
endingStyle = "CAP_ROUND"
);
![polyline2d](images/lib3x-polyline2d-2.JPG)
use <polyline2d.scad>;
$fn = 24;
polyline2d(points = [[1, 2], [-5, -4], [-5, 3], [5, 5]], width = 1,
startingStyle = "CAP_ROUND", endingStyle = "CAP_ROUND");
polyline2d(
points = [[1, 2], [-5, -4], [-5, 3], [5, 5]],
width = 1,
startingStyle = "CAP_ROUND",
endingStyle = "CAP_ROUND"
);
![polyline2d](images/lib3x-polyline2d-3.JPG)

View File

@@ -21,12 +21,10 @@ Transforms a point inside a rectangle to a point of an arc.
radius = 20;
angle = 180;
for(i = [0:len(t) - 1]) {
for(pt = vx_ascii(t[i], invert = true)) {
for(i = [0:len(t) - 1], pt = vx_ascii(t[i], invert = true)) {
bended = ptf_bend(size, pt + [i * 8, 0], radius, angle);
translate(bended)
sphere(0.5, $fn = 24);
}
}
![ptf_bend](images/lib3x-ptf_bend-1.JPG)

View File

@@ -29,18 +29,17 @@ It solidifies two surfaces with triangular mesh.
use <surface/sf_solidifyT.scad>;
thickness = .2;
a_step = 10;
a_step = 15;
r_step = 0.2;
scale = 100;
function f(x, y) = (pow(y,2)/pow(2, 2))-(pow(x,2)/pow(2, 2));
function f(x, y) = (y ^ 2 - x ^ 2) / 4;
pts2d = [
for(a = [a_step:a_step:360])
for(r = [r_step:r_step:2])
for(a = [a_step:a_step:360], r = [r_step:r_step:2])
let(
x = round(r * cos(a) * 100) / 100,
y = round(r * sin(a) * 100) / 100
x = r * cos(a),
y = r * sin(a)
)
[x, y]
];
@@ -49,7 +48,6 @@ It solidifies two surfaces with triangular mesh.
points2 = [for(p = points1) [p.x, p.y, p.z - scale * thickness]];
triangles = tri_delaunay(pts2d);
sf_solidifyT(points1, points2, triangles);
![sf_solidifyT](images/lib3x-sf_solidifyT-2.JPG)

View File

@@ -28,10 +28,8 @@ It thickens a surface, described by a m * n list of `[x, y, z]`s.
use <surface/sf_thicken.scad>;
function f(x, y) =
30 * (
cos(sqrt(pow(x, 2) + pow(y, 2))) +
cos(3 * sqrt(pow(x, 2) + pow(y, 2)))
);
let(leng = norm([x, y]))
30 * (cos(leng) + cos(3 * leng));
thickness = 3;
min_value = -200;

View File

@@ -36,7 +36,8 @@ Returns shape points of two splitting liquid shapes, kind of how cells divide. T
shape_pts = shape_liquid_splitting(radius, centre_dist);
width = centre_dist / 2 + radius;
rotate_extrude() difference() {
rotate_extrude()
difference() {
polygon(shape_pts);
translate([-width, -radius])

View File

@@ -14,21 +14,30 @@ Returns shape points of a [Superformula](https://en.wikipedia.org/wiki/Superform
phi_step = 0.05;
polygon(shape_superformula(phi_step, 3, 3, 4.5, 10, 10));
translate([3, 0])
polygon(shape_superformula(phi_step, 4, 4, 12, 15, 15));
translate([6, 0])
polygon(shape_superformula(phi_step, 7, 7, 10, 6, 6));
translate([9, 0])
polygon(shape_superformula(phi_step, 5, 5, 4, 4, 4));
translate([0, -4])
scale(0.8) polygon(shape_superformula(phi_step, 5, 5, 2, 7, 7));
scale(0.8)
polygon(shape_superformula(phi_step, 5, 5, 2, 7, 7));
translate([3, -4])
scale(0.25) polygon(shape_superformula(phi_step, 5, 5, 2, 13, 13));
scale(0.25)
polygon(shape_superformula(phi_step, 5, 5, 2, 13, 13));
translate([6, -4])
polygon(shape_superformula(phi_step, 4, 4, 1, 1, 1));
translate([9, -4])
scale(0.3) polygon(shape_superformula(phi_step, 4, 4, 1, 7, 8));
scale(0.3)
polygon(shape_superformula(phi_step, 4, 4, 1, 7, 8));
![shape_superformula](images/lib3x-shape_superformula-1.JPG)

View File

@@ -19,13 +19,15 @@ The 2D polygon should center at the origin and you have to determine the side le
stereographic_extrude(shadow_side_leng = dimension, convexity = 10)
text(
"M", size = dimension,
valign = "center", halign = "center"
valign = "center",
halign = "center"
);
color("black")
text(
"M", size = dimension,
valign = "center", halign = "center"
valign = "center",
halign = "center"
);
![stereographic_extrude](images/lib3x-stereographic_extrude-1.JPG)

View File

@@ -55,8 +55,6 @@ Create a 3D version of [Voronoi diagram](https://en.wikipedia.org/wiki/Voronoi_d
]
];
thickness = 2;
difference() {
sphere(r);

View File

@@ -26,11 +26,13 @@ Given a list of 0s and 1s that represent a black-and-white image. This function
]);
for(pt = pts) {
translate(pt) square(1);
translate(pt)
square(1);
}
translate([8, 0]) for(pt = pts) {
translate(pt) text("A", font="Arial Black", 1);
translate(pt)
text("A", font="Arial Black", 1);
}
![vx_from](images/lib3x-vx_from-1.JPG)