in reply to Interpolating data slope for multiple points

A little while ago, I needed to find the rotation angle of a flat object in an image, so sampling the edge and finding the line was the way to go. What I eventually went with was:

use strict; use warnings; use Statistics::LineFit; use Math::Trig; ... my $lineFit = Statistics::LineFit->new(); my @x = map {$_->{col}} @edgeSamples; my @y = map {$_->{row}} @edgeSamples; unless ($lineFit->setData(\@x, \@y)) { print "Invalid data sample for regression; could not calculate + skew for $inFile\n"; next; } ... my ($intercept, $slope) = $lineFit->coefficients(); my $angle = atan($slope); $angle *= 180/3.14159265359; ...

Now, that does linear interpolation, but I would expect mass loss to be more of a noisy exponential decay towards the final value than linear. If it turns out to actually be a problem you could try resorting to piecewise linear interpolation, or use a fancy high-order plotting package.

Replies are listed 'Best First'.
Re^2: Interpolating data slope for multiple points
by oko1 (Deacon) on Sep 17, 2010 at 17:12 UTC

    Thanks for your reply. I was actually trying to learn and understand how this process works, but it's good to know there are Magic Black Boxes that can do it. Assuming I can understand the math in the docs, anyway. :)


    --
    "Language shapes the way we think, and determines what we can think about."
    -- B. L. Whorf