From a5753d7953982234317ade005097987069cf0e1c Mon Sep 17 00:00:00 2001 From: Adrian Mariano Date: Sat, 13 Jun 2020 22:35:22 -0400 Subject: [PATCH] Added non-uniform sampling to deriv and uniform option to path_tangents, and path_segment_lengths. --- math.scad | 28 ++++++++++++++++++++++++++++ paths.scad | 45 +++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 69 insertions(+), 4 deletions(-) diff --git a/math.scad b/math.scad index 10938ab..5ec3209 100644 --- a/math.scad +++ b/math.scad @@ -899,7 +899,13 @@ function count_true(l, nmax=undef, i=0, cnt=0) = // data[len(data)-1]. This function uses a symetric derivative approximation // for internal points, f'(t) = (f(t+h)-f(t-h))/2h. For the endpoints (when closed=false) the algorithm // uses a two point method if sufficient points are available: f'(t) = (3*(f(t+h)-f(t)) - (f(t+2*h)-f(t+h)))/2h. +// +// If `h` is a vector then it is assumed to be nonuniform, with h[i] giving the sampling distance +// between data[i+1] and data[i], and the data values will be linearly resampled at each corner +// to produce a uniform spacing for the derivative estimate. At the endpoints a single point method +// is used: f'(t) = (f(t+h)-f(t))/h. function deriv(data, h=1, closed=false) = + is_vector(h) ? _deriv_nonuniform(data, h, closed=closed) : let( L = len(data) ) closed? [ for(i=[0:1:L-1]) @@ -919,6 +925,28 @@ function deriv(data, h=1, closed=false) = ]; +function _dnu_calc(f1,fc,f2,h1,h2) = + let( + f1 = h2