mirror of
https://github.com/BelfrySCAD/BOSL2.git
synced 2024-12-29 16:29:40 +00:00
Added median()
This commit is contained in:
parent
412dd9e260
commit
3ac23e15e6
2 changed files with 35 additions and 16 deletions
23
math.scad
23
math.scad
|
@ -519,8 +519,8 @@ function product(v, i=0, tot=undef) = i>=len(v)? tot : product(v, i+1, ((tot==un
|
|||
|
||||
// Function: mean()
|
||||
// Description:
|
||||
// Returns the mean of all entries in the given array.
|
||||
// If passed an array of vectors, returns a vector of mean of each part.
|
||||
// Returns the arithmatic mean/average of all entries in the given array.
|
||||
// If passed a list of vectors, returns a vector of the mean of each part.
|
||||
// Arguments:
|
||||
// v = The list of values to get the mean of.
|
||||
// Example:
|
||||
|
@ -529,6 +529,25 @@ function product(v, i=0, tot=undef) = i>=len(v)? tot : product(v, i+1, ((tot==un
|
|||
function mean(v) = sum(v)/len(v);
|
||||
|
||||
|
||||
// Function: median()
|
||||
// Usage:
|
||||
// x = median(v);
|
||||
// Description:
|
||||
// Given a list of numbers or vectors, finds the median value or midpoint.
|
||||
// If passed a list of vectors, returns the vector of the median of each part.
|
||||
function median(v) =
|
||||
assert(is_list(v))
|
||||
assert(len(v)>0)
|
||||
is_vector(v[0])? (
|
||||
assert(is_consistent(v))
|
||||
[
|
||||
for (i=idx(v[0]))
|
||||
let(vals = subindex(v,i))
|
||||
(min(vals)+max(vals))/2
|
||||
]
|
||||
) : (min(v)+max(v))/2;
|
||||
|
||||
|
||||
// Section: Matrix math
|
||||
|
||||
// Function: linear_solve()
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
BOSL_VERSION = [2,0,197];
|
||||
BOSL_VERSION = [2,0,198];
|
||||
|
||||
|
||||
// Section: BOSL Library Version Functions
|
||||
|
|
Loading…
Reference in a new issue