use warnings; use strict; use feature ':5.10'; my @accel = ([-0.7437,0.1118,-0.5367], [-0.5471,0.0062,-0.6338], [-0.6437,0.1216,-0.5255], [-0.4437,0.3216,-0.3255], ); # note: I changed from an array whose only element is an arrayref of arrayrefs to an array who has n arrayrefs, to be a simple 2D array use Math::Spline; my (@x,@y,@z,@t); # generate x, y, and z arrays, and a t array my $pt = 0; for my $xyz (@accel) { push @t, $pt++; push @x, $xyz->[0]; push @y, $xyz->[1]; push @z, $xyz->[2]; } # create spline calculators for x&y and x&z my $spline_tx = eval { Math::Spline::->new(\@t, \@x) } or do { die "ty: $@" }; my $spline_ty = eval { Math::Spline::->new(\@t, \@y) } or do { die "ty: $@" }; my $spline_tz = eval { Math::Spline::->new(\@t, \@z) } or do { die "tz: $@" }; my @interp_accel = (); my $NSTEPS = 200; my $dt = $pt/$NSTEPS; # $NSTEPS+1 values from xmin to xmax, inclusive for my $i (0..$NSTEPS) { my $t = $i * $dt; my $x = $spline_tx->evaluate($t); my $y = $spline_ty->evaluate($t); my $z = $spline_tz->evaluate($t); push @interp_accel, [$x,$y,$z]; # store for later printf "interpolate # %d => t=%.2f => [%s,%s,%s]\n", $i, map {$_//''} $t, $x, $y, $z; # debug print }