Interpolation Methods: Paul Bourke
Interpolation Methods: Paul Bourke
Discussed here are a number of interpolation methods, this is by no means an exhaustive list
but the methods shown tend to be those in common use in computer graphics. The main
attributes is that they are easy to compute and are stable. Interpolation as used here is
different to "smoothing", the techniques discussed here have the characteristic that the
estimated curve passes through all the given points. The idea is that the points are in some
sense correct and lie on an underlying but unknown curve, the problem is to be able to
estimate the values of the curve at any position between the known points.
Linear interpolation is the simplest Linear
method of getting values at
positions in between the data
points. The points are simply joined
by straight line segments. Each
segment (bounded by two data
points) can be interpolated
independently. The parameter mu
defines where to estimate the value
on the interpolated line, it is 0 at the
first point and 1 and the second
point. For interpolated values
between the two points mu ranges
between 0 and 1. Values of mu
Cosine
outside this range result in
extrapolation. This convention is
followed for all the subsequent
methods below. As with subsequent
more interesting methods, a snippet
of plain C code will server to
describe the mathematics.
double LinearInterpolate(
double y1,double y2,
double mu)
{
return(y1*(1-mu)+y2*mu);
}
Cubic
double CosineInterpolate(
double y1,double y2,
double mu)
{
double mu2;
mu2 = (1-cos(mu*PI))/2;
return(y1*(1mu2)+y2*mu2);
}
y1)*(1+bias)*(1-tension)/2;
m1 += (y3-y2)*(1bias)*(1-tension)/2;
a0 = 2*mu3 - 3*mu2 + 1;
a1 =
mu3 - 2*mu2 + mu;
a2 =
mu3 mu2;
a3 = -2*mu3 + 3*mu2;
return(a0*y1+a1*m0+a2*m1+a3*
y2);
}
Trilinear Interpolation
Written by Paul Bourke
July 1997
Trilinear interpolation is the name given to the process of linearly interpolating points within
a box (3D) given values at the vertices of the box. Perhaps its most common application is
interpolating within cells of a volumetric dataset.
Consider a unit cube with the
lower/left/base vertex at the origin as
shown here on the right.
The values at each vertex will be
denoted V000, V100, V010, ....etc....V111
The value at position (x,y,z) within the cube will be denoted Vxyz and is given by
Vxyz = V000 (1 - x) (1 - y) (1 - z) +
V100 x (1 - y) (1 - z) +
V010 (1 - x) y (1 - z) +
V001 (1 - x) (1 - y) z +
V101 x (1 - y) z +
V011 (1 - x) y z +
V110 x y (1 - z) +
V111 x y z
In general the box will not be of unit size nor will it be aligned at the origin. Simple
translation and scaling (possibly of each axis independently) can be used to transform into
and then out of this simplified situation.
Linear Regression
Written by Paul Bourke
October 1998
Linear regression is a method to best fit a linear equation (straight line) of the form y(x) = a +
b x to a collection of N points (xi,yi). Where b is the slope and a the intercept on the y axis.
The result will be stated below without derivation, that requires minimisation of the sum of
the squared distance from the data points and the proposed line. This function is minimised
by calculating the derivative with respect to a and b and setting these to zero. For a more
complete derivation see the "Numerical Recipes in C".
The solution is clearer if we define the following
Then
and
Note
This discussion assumes there is no known variance for the x and y values. There are
solutions which can take this into account, this is particularly important if some values
are known with less error than others.
The solution above requires that the slope is not infinite, Sxx is not zero.
Example
The following example shows the points and the best fit line as determined using the
techniques discussed here.
Source
C
linregress.c
C++ contributed by Charles Brown
RegressionLine.cpp
RegressionLine.hpp
The following introduces a method of immediately deriving a polynomial that passes through
an arbitrary number of points. That is, find a polynomial f(x) that passes through the N points
(x0,y0), (x1,y1), (x2,y2), ..... (xN-1,yN-1)
The key to this solution is that we want an exact fit at the points given and we don't care what
happens in between those points. The general solution is
To see how this works, consider the product term. When x = xi the product term has the same
denominator and numerator and thus equals 1 and therefore contributes yi to the sum. All
other terms in the summation contribute 0 since there exists a (xj - xj) in the numerator.
Thanks to Simon Stegmaier for pointing out that this is known as a Lagrange Polynomial.
For a numerical example consider the polynomial that passes through the following points
(0,2)
(1,1)
(3,3)
(4,0)
(6,5)
2 * (x-1) * (x-3) * (x-4) * (x-6) / [ (0-1) * (0-3) * (0-4) * (01 * (x-0) * (x-3) * (x-4) * (x-6) / [ (1-0) * (1-3) * (1-4) * (13 * (x-0) * (x-1) * (x-4) * (x-6) / [ (3-0) * (3-1) * (3-4) * (30 * (x-0) * (x-1) * (x-3) * (x-6) / [ (4-0) * (4-1) * (4-3) * (45 * (x-0) * (x-1) * (x-3) * (x-4) / [ (6-0) * (6-1) * (6-3) * (6-
f(x) =
+
+
(x-1)
(x-0)
(x-0)
(x-0)
*
*
*
*
(x-3)
(x-3)
(x-1)
(x-1)
*
*
*
*
(x-4)
(x-4)
(x-4)
(x-3)
*
*
*
*
(x-6)
(x-6)
(x-6)
(x-4)
/
/
/
/
36
30
6
36
By substituting the values of x for the points the function must pass through (x=0,1,3,4,6) it is
easy to see that the expression above achieves the result, namely y=2,1,3,0,5 respectively.
What happens at other points?
All bets are off regarding the behavior between the fixed points. The polynomial is of degree
N and could violently fly off anywhere. The continuous curve for the numerical example
above is shown below.
X-NNTP-Posting-Host: 209.63.114.134
Hi everyone,
My name is John Santos and I am willing to pay anyone $100.00 for the first
person to solve this problem. I am providing some hints. This works as
follows:
you will see nine digits - the tenth digit or letter is the answer.
What I need is the formula or mathematical equation to get there...
Number
Answer
--------------------------749736637
1
713491024
8
523342792
D
749236871
P
727310078
E
746261832
4
733237527
L
743510589
9
715240338
K
722592910
1
739627071
R
The first one with the answer and emails it to me wins the $100.00
Email address: [email protected]
Good Luck !!!!
749736637)
713491024)
523342792)
749236871)
727310078)
746261832)
733237527)
743510589)
715240338)
722592910)
739627071)
=
=
=
=
=
=
=
=
=
=
=
49
56
68
80
69
52
76
57
75
49
82
(1)
(8)
(D)
(P)
(E)
(4)
(L)
(9)
(K)
(1)
(R)