From 6b02a595a2f4fdde77273e935e4135e3416d8149 Mon Sep 17 00:00:00 2001 From: Adrian Mariano Date: Fri, 25 Mar 2022 23:35:07 -0400 Subject: [PATCH] add exponential dist, IDENT constant doc fixes --- constants.scad | 5 +++++ math.scad | 21 +++++++++++++-------- rounding.scad | 8 ++++---- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/constants.scad b/constants.scad index 2253af2..003434a 100644 --- a/constants.scad +++ b/constants.scad @@ -215,4 +215,9 @@ RAY = [true, false]; LINE = [false, false]; +// Constant: IDENT +// Description: Identity transformation matrix for three-dimensional transforms. Equal to `ident(4)`. +IDENT=ident(4); + + // vim: expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap diff --git a/math.scad b/math.scad index 9a05a74..7f5c746 100644 --- a/math.scad +++ b/math.scad @@ -567,17 +567,22 @@ function gaussian_rands(n=1, mean=0, cov=1, seed=undef) = move(mean,list_to_matrix(rdata,dim)*transpose(L)); -// Function: spherical_random_points() +// Function: exponential_rands() // Usage: -// points = spherical_random_points([n], [radius], [seed]); -// See Also: random_polygon(), random_points() -// Topics: Random, Points +// arr = exponential_rands([n], [lambda], [seed]) // Description: -// Generate `n` 3D uniformly distributed random points lying on a sphere centered at the origin with radius equal to `radius`. +// Returns random numbers with an exponential distribution with parameter lambda, and hence mean 1/lambda. // Arguments: -// n = number of points to generate. Default: 1 -// radius = the sphere radius. Default: 1 -// seed = an optional seed for the random generation. +// n = number of points to return. Default: 1 +// lambda = distribution parameter. The mean will be 1/lambda. Default: 1 +function exponential_rands(n=1, lambda=1, seed) = + assert( is_int(n) && n>=1, "The number of points should be an integer greater than zero.") + assert( is_num(lambda) && lambda>0, "The lambda parameter must be a positive number.") + let( + unif = is_def(seed) ? rands(0,1,n,seed=seed) : rands(0,1,n) + ) + -(1/lambda) * [for(x=unif) ln(1-x)]; + // See https://mathworld.wolfram.com/SpherePointPicking.html function spherical_random_points(n=1, radius=1, seed) = diff --git a/rounding.scad b/rounding.scad index afef75d..41ef49a 100644 --- a/rounding.scad +++ b/rounding.scad @@ -31,7 +31,7 @@ include // . // For circular rounding you can use the `radius` or `r` parameter to set the rounding radius. // . -// For chamfers you can use `length` to set the length of the chamfer. +// For chamfers you can use `width` to set the width of the chamfer. // . // The "smooth" rounding method also has a parameter that specifies how smooth the curvature match is. This parameter, `k`, // ranges from 0 to 1, with a default of 0.5. Larger values gives a more @@ -153,7 +153,7 @@ include // away from the corner along the path where the roundover or chamfer should start. This makes it easy to ensure your roundover will fit, // so use it if you want the largest possible roundover. // * For circular rounding you can use the `radius` or `r` parameter to set the rounding radius. -// * For chamfers you can use the `length` parameter, which sets the length of the chamfer edge. +// * For chamfers you can use the `width` parameter, which sets the width of the chamfer edge. // . // As explained in [Types of Roundover](rounding.scad#subsection-types-of-roundover), the continuous curvature "smooth" // type of rounding also accepts the `k` parameter, between 0 and 1, which specifies how fast the curvature changes at @@ -198,7 +198,7 @@ include // radius/r = rounding radius, only compatible with `method="circle"`. Can be a number or vector. // cut = rounding cut distance, compatible with all methods. Can be a number or vector. // joint = rounding joint distance, compatible with `method="chamfer"` and `method="smooth"`. Can be a number or vector. -// flat = length of the flat edge created by chamfering, compatible with `method="chamfer"`. Can be a number of vector. +// width = width of the flat edge created by chamfering, compatible with `method="chamfer"`. Can be a number or vector. // k = continuous curvature smoothness parameter for `method="smooth"`. Can be a number or vector. Default: 0.5 // closed = if true treat the path as a closed polygon, otherwise treat it as open. Default: true. // verbose = if true display rounding scale factors that show how close roundovers are to overlapping. Default: false @@ -321,7 +321,7 @@ include // path_len = path_segment_lengths(path,closed=true); // halflen = [for(i=idx(path)) min(select(path_len,i-1,i))/2]; // polygon(round_corners(path,joint = halflen, method="circle",verbose=true)); -// Example(2D): Chamfering, specifying the chamfer length +// Example(2D): Chamfering, specifying the chamfer width // path = star(5, step=2, d=100); // path2 = round_corners(path, method="chamfer", width=5); // polygon(path2);