more usage updates

This commit is contained in:
Adrian Mariano 2022-03-31 18:36:09 -04:00
parent 7afef10a79
commit 95cdbfa34b
2 changed files with 29 additions and 22 deletions

View file

@ -142,7 +142,7 @@ function sqr(x) =
// Function: log2() // Function: log2()
// Usage: // Usage:
// foo = log2(x); // val = log2(x);
// Description: // Description:
// Returns the logarithm base 2 of the value given. // Returns the logarithm base 2 of the value given.
// Example: // Example:
@ -565,12 +565,11 @@ function median(v) =
// Function: deltas() // Function: deltas()
// Usage: // Usage:
// delts = deltas(v); // delts = deltas(v,[wrap]);
// Description: // Description:
// Returns a list with the deltas of adjacent entries in the given list, optionally wrapping back to the front. // Returns a list with the deltas of adjacent entries in the given list, optionally wrapping back to the front.
// The list should be a consistent list of numeric components (numbers, vectors, matrix, etc). // The list should be a consistent list of numeric components (numbers, vectors, matrix, etc).
// Given [a,b,c,d], returns [b-a,c-b,d-c]. // Given [a,b,c,d], returns [b-a,c-b,d-c].
//
// Arguments: // Arguments:
// v = The list to get the deltas of. // v = The list to get the deltas of.
// wrap = If true, wrap back to the start from the end. ie: return the difference between the last and first items as the last delta. Default: false // wrap = If true, wrap back to the start from the end. ie: return the difference between the last and first items as the last delta. Default: false
@ -748,7 +747,7 @@ function rand_int(minval, maxval, n, seed=undef) =
// Function: random_points() // Function: random_points()
// Usage: // Usage:
// points = random_points([n], [dim], [scale], [seed]); // points = random_points(n, dim, [scale], [seed]);
// See Also: random_polygon(), spherical_random_points() // See Also: random_polygon(), spherical_random_points()
// Topics: Random, Points // Topics: Random, Points
// Description: // Description:
@ -760,7 +759,7 @@ function rand_int(minval, maxval, n, seed=undef) =
// dim = dimension of the points. Default: 2 // dim = dimension of the points. Default: 2
// scale = the scale of the point coordinates. Default: 1 // scale = the scale of the point coordinates. Default: 1
// seed = an optional seed for the random generation. // seed = an optional seed for the random generation.
function random_points(n, dim=2, scale=1, seed) = function random_points(n, dim, scale=1, seed) =
assert( is_int(n) && n>=0, "The number of points should be a non-negative integer.") assert( is_int(n) && n>=0, "The number of points should be a non-negative integer.")
assert( is_int(dim) && dim>=1, "The point dimensions should be an integer greater than 1.") assert( is_int(dim) && dim>=1, "The point dimensions should be an integer greater than 1.")
assert( is_finite(scale) || is_vector(scale,dim), "The scale should be a number or a vector with length equal to d.") assert( is_finite(scale) || is_vector(scale,dim), "The scale should be a number or a vector with length equal to d.")
@ -848,7 +847,7 @@ function spherical_random_points(n=1, radius=1, seed) =
// Function: random_polygon() // Function: random_polygon()
// Usage: // Usage:
// points = random_polygon(n, size, [seed]); // points = random_polygon([n], [size], [seed]);
// See Also: random_points(), spherical_random_points() // See Also: random_points(), spherical_random_points()
// Topics: Random, Polygon // Topics: Random, Polygon
// Description: // Description:

View file

@ -14,7 +14,7 @@
// Function&Module: half_of() // Function&Module: half_of()
// //
// Usage: as module // Usage: as module
// half_of(v, [cp], [s], [planar]) ... // half_of(v, [cp], [s], [planar]) CHILDREN;
// Usage: as function // Usage: as function
// result = half_of(p,v,[cp]); // result = half_of(p,v,[cp]);
// //
@ -40,6 +40,7 @@
// half_of([1,1], planar=true) circle(d=50); // half_of([1,1], planar=true) circle(d=50);
module half_of(v=UP, cp, s=100, planar=false) module half_of(v=UP, cp, s=100, planar=false)
{ {
req_children($children);
cp = is_vector(v,4)? assert(cp==undef, "Don't use cp with plane definition.") plane_normal(v) * v[3] : cp = is_vector(v,4)? assert(cp==undef, "Don't use cp with plane definition.") plane_normal(v) * v[3] :
is_vector(cp)? cp : is_vector(cp)? cp :
is_num(cp)? cp*unit(v) : is_num(cp)? cp*unit(v) :
@ -119,8 +120,8 @@ function half_of(p, v=UP, cp) =
// Function&Module: left_half() // Function&Module: left_half()
// //
// Usage: as module // Usage: as module
// left_half([s], [x]) ... // left_half([s], [x]) CHILDREN;
// left_half(planar=true, [s], [x]) ... // left_half(planar=true, [s], [x]) CHILDREN;
// Usage: as function // Usage: as function
// result = left_half(p, [x]); // result = left_half(p, [x]);
// //
@ -142,6 +143,7 @@ function half_of(p, v=UP, cp) =
// left_half(planar=true) circle(r=20); // left_half(planar=true) circle(r=20);
module left_half(s=100, x=0, planar=false) module left_half(s=100, x=0, planar=false)
{ {
req_children($children);
dir = LEFT; dir = LEFT;
difference() { difference() {
children(); children();
@ -161,10 +163,10 @@ function left_half(p,x=0) = half_of(p, LEFT, [x,0,0]);
// Function&Module: right_half() // Function&Module: right_half()
// //
// Usage: as module // Usage: as module
// right_half([s=], [x=]) ... // right_half([s=], [x=]) CHILDREN;
// right_half(planar=true, [s=], [x=]) ... // right_half(planar=true, [s=], [x=]) CHILDREN;
// Usage: as function // Usage: as function
// result = right_half(p=, [x=]); // result = right_half(p, [x=]);
// //
// Description: // Description:
// Slices an object at a vertical Y-Z cut plane, and masks away everything that is left of it. // Slices an object at a vertical Y-Z cut plane, and masks away everything that is left of it.
@ -202,8 +204,8 @@ function right_half(p,x=0) = half_of(p, RIGHT, [x,0,0]);
// Function&Module: front_half() // Function&Module: front_half()
// //
// Usage: // Usage:
// front_half([s], [y]) ... // front_half([s], [y]) CHILDREN;
// front_half(planar=true, [s], [y]) ... // front_half(planar=true, [s], [y]) CHILDREN;
// Usage: as function // Usage: as function
// result = front_half(p, [y]); // result = front_half(p, [y]);
// //
@ -224,6 +226,7 @@ function right_half(p,x=0) = half_of(p, RIGHT, [x,0,0]);
// front_half(planar=true) circle(r=20); // front_half(planar=true) circle(r=20);
module front_half(s=100, y=0, planar=false) module front_half(s=100, y=0, planar=false)
{ {
req_children($children);
dir = FWD; dir = FWD;
difference() { difference() {
children(); children();
@ -243,8 +246,8 @@ function front_half(p,y=0) = half_of(p, FRONT, [0,y,0]);
// Function&Module: back_half() // Function&Module: back_half()
// //
// Usage: // Usage:
// back_half([s], [y]) ... // back_half([s], [y]) CHILDREN;
// back_half(planar=true, [s], [y]) ... // back_half(planar=true, [s], [y]) CHILDREN;
// Usage: as function // Usage: as function
// result = back_half(p, [y]); // result = back_half(p, [y]);
// //
@ -265,6 +268,7 @@ function front_half(p,y=0) = half_of(p, FRONT, [0,y,0]);
// back_half(planar=true) circle(r=20); // back_half(planar=true) circle(r=20);
module back_half(s=100, y=0, planar=false) module back_half(s=100, y=0, planar=false)
{ {
req_children($children);
dir = BACK; dir = BACK;
difference() { difference() {
children(); children();
@ -284,7 +288,7 @@ function back_half(p,y=0) = half_of(p, BACK, [0,y,0]);
// Function&Module: bottom_half() // Function&Module: bottom_half()
// //
// Usage: // Usage:
// bottom_half([s], [z]) ... // bottom_half([s], [z]) CHILDREN;
// Usage: as function // Usage: as function
// result = bottom_half(p, [z]); // result = bottom_half(p, [z]);
// //
@ -302,6 +306,7 @@ function back_half(p,y=0) = half_of(p, BACK, [0,y,0]);
// bottom_half(z=-10) sphere(r=20); // bottom_half(z=-10) sphere(r=20);
module bottom_half(s=100, z=0) module bottom_half(s=100, z=0)
{ {
req_children($children);
dir = DOWN; dir = DOWN;
difference() { difference() {
children(); children();
@ -316,8 +321,9 @@ function bottom_half(p,z=0) = half_of(p,BOTTOM,[0,0,z]);
// Function&Module: top_half() // Function&Module: top_half()
// //
// Usage: // Usage: as module
// top_half([s], [z]) ... // top_half([s], [z]) CHILDREN;
// Usage: as function
// result = top_half(p, [z]); // result = top_half(p, [z]);
// //
// Description: // Description:
@ -334,6 +340,7 @@ function bottom_half(p,z=0) = half_of(p,BOTTOM,[0,0,z]);
// top_half(z=5) sphere(r=20); // top_half(z=5) sphere(r=20);
module top_half(s=100, z=0) module top_half(s=100, z=0)
{ {
req_children($children);
dir = UP; dir = UP;
difference() { difference() {
children(); children();
@ -392,7 +399,7 @@ function _partition_cutpath(l, h, cutsize, cutpath, gap) =
// Module: partition_mask() // Module: partition_mask()
// Usage: // Usage:
// partition_mask(l, w, h, [cutsize], [cutpath], [gap], [inverse], [spin], [orient],); // partition_mask(l, w, h, [cutsize], [cutpath], [gap], [inverse], [spin], [orient]) [ATTACHMENTS];
// Description: // Description:
// Creates a mask that you can use to difference or intersect with an object to remove half of it, leaving behind a side designed to allow assembly of the sub-parts. // Creates a mask that you can use to difference or intersect with an object to remove half of it, leaving behind a side designed to allow assembly of the sub-parts.
// Arguments: // Arguments:
@ -442,7 +449,7 @@ module partition_mask(l=100, w=100, h=100, cutsize=10, cutpath="jigsaw", gap=0,
// Module: partition_cut_mask() // Module: partition_cut_mask()
// Usage: // Usage:
// partition_cut_mask(l, w, h, [cutsize], [cutpath], [gap], [inverse], [spin], [orient]); // partition_cut_mask(l, w, h, [cutsize], [cutpath], [gap], [inverse], [spin], [orient]) [ATTACHMENTS];
// Description: // Description:
// Creates a mask that you can use to difference with an object to cut it into two sub-parts that can be assembled. // Creates a mask that you can use to difference with an object to cut it into two sub-parts that can be assembled.
// The `$slop` value is important to get the proper fit and should probably be smaller than 0.2. The examples below // The `$slop` value is important to get the proper fit and should probably be smaller than 0.2. The examples below
@ -485,7 +492,7 @@ module partition_cut_mask(l=100, h=100, cutsize=10, cutpath="jigsaw", gap=0, anc
// Module: partition() // Module: partition()
// Usage: // Usage:
// partition(size, [spread], [cutsize], [cutpath], [gap], [spin]) ... // partition(size, [spread], [cutsize], [cutpath], [gap], [spin]) CHILDREN;
// Description: // Description:
// Partitions an object into two parts, spread apart a small distance, with matched joining edges. // Partitions an object into two parts, spread apart a small distance, with matched joining edges.
// Arguments: // Arguments:
@ -510,6 +517,7 @@ module partition_cut_mask(l=100, h=100, cutsize=10, cutpath="jigsaw", gap=0, anc
// partition(cutpath="jigsaw") cylinder(h=50, d=80, center=false); // partition(cutpath="jigsaw") cylinder(h=50, d=80, center=false);
module partition(size=100, spread=10, cutsize=10, cutpath="jigsaw", gap=0, spin=0) module partition(size=100, spread=10, cutsize=10, cutpath="jigsaw", gap=0, spin=0)
{ {
req_children($children);
size = is_vector(size)? size : [size,size,size]; size = is_vector(size)? size : [size,size,size];
cutsize = is_vector(cutsize)? cutsize : [cutsize*2, cutsize]; cutsize = is_vector(cutsize)? cutsize : [cutsize*2, cutsize];
rsize = v_abs(rot(spin,p=size)); rsize = v_abs(rot(spin,p=size));