mirror of
https://github.com/BelfrySCAD/BOSL2.git
synced 2024-12-29 16:29:40 +00:00
Added deltas()
This commit is contained in:
parent
09e89e9182
commit
e946031d99
1 changed files with 14 additions and 2 deletions
16
math.scad
16
math.scad
|
@ -226,10 +226,10 @@ function atanh(x) = ln((1+x)/(1-x))/2;
|
|||
|
||||
// Function: sum()
|
||||
// Description:
|
||||
// Returns the sum of all entries in the given array.
|
||||
// Returns the sum of all entries in the given list.
|
||||
// If passed an array of vectors, returns a vector of sums of each part.
|
||||
// Arguments:
|
||||
// v = The vector to get the sum of.
|
||||
// v = The list to get the sum of.
|
||||
// Example:
|
||||
// sum([1,2,3]); // returns 6.
|
||||
// sum([[1,2,3], [3,4,5], [5,6,7]]); // returns [9, 12, 15]
|
||||
|
@ -263,6 +263,18 @@ function sum_of_sines(a, sines) =
|
|||
]);
|
||||
|
||||
|
||||
// Function: deltas()
|
||||
// Description:
|
||||
// Returns a list with the deltas of adjacent entries in the given list.
|
||||
// Given [a,b,c,d], returns [b-a,c-b,d-c].
|
||||
// Arguments:
|
||||
// v = The list to get the deltas of.
|
||||
// Example:
|
||||
// deltas([2,5,9,17]); // returns [3,4,8].
|
||||
// deltas([[1,2,3], [3,6,8], [4,8,11]]); // returns [[2,4,5], [1,2,3]]
|
||||
function deltas(v) = len(v)<2? v : [for (p=pair(v)) p.y-p.x];
|
||||
|
||||
|
||||
// Function: mean()
|
||||
// Description:
|
||||
// Returns the mean of all entries in the given array.
|
||||
|
|
Loading…
Reference in a new issue