use warnings; use strict; use feature ':5.10'; my @accel = ([-0.7437,0.1118,-0.5367], [-0.5471,0.0062,-0.6338], [-0.7437,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); my ($xmin, $xmax) = (9.99e99,-9.99e99); # for tracking min and max x values # generate x, y, and z arrays for my $xyz (@accel) { push @x, $xyz->[0]; push @y, $xyz->[1]; push @z, $xyz->[2]; if($x[-1] < $xmin) { $xmin = $x[-1]; } if($x[-1] > $xmax) { $xmax = $x[-1]; } } # create spline calculators for x&y and x&z my $spline_xy = eval { Math::Spline::->new(\@x, \@y) } or do { die "xy: $@" }; my $spline_xz = eval { Math::Spline::->new(\@x, \@z) } or do { die "yz: $@" }; my @interp_accel = (); my $NSTEPS = 200; my $dx = ($xmax-$xmin)/$NSTEPS; # $NSTEPS+1 values from xmin to xmax, inclusive for my $i (0..$NSTEPS) { my $x = $xmin + $dx * $i; my $y = defined($spline_xy) ? $spline_xy->evaluate($x) : undef; my $z = defined($spline_xz) ? $spline_xz->evaluate($x) : undef; push @interp_accel, [$x,$y,$z]; # store for later printf "interpolate # %d => [%s,%s,%s]\n", $i, map {$_//''} $x, $y, $z; # debug print }