# Linear interpolation

1. Feb 18, 2008

### Bucky

Hi, I'm implimenting a method presented in

http://www.dgp.toronto.edu/people/stam/reality/Research/pdf/GDC03.pdf

Part of the way through it it presents a linear interpolation method, which I wanted to expand to three dimensions, but I don't understand how it works in two dimensions.

I've done linear interpolation before, but this seems very different:

Code (Text):

void advect ( int N, int b, float * d, float * d0, float * u, float * v, float dt )
{
int i, j, i0, j0, i1, j1;
float x, y, s0, t0, s1, t1, dt0;
dt0 = dt*N;
for ( i=1 ; i<=N ; i++ ) {
for ( j=1 ; j<=N ; j++ ) {
x = i-dt0*u[IX(i,j)]; y = j-dt0*v[IX(i,j)];
if (x<0.5) x=0.5; if (x>N+0.5) x=N+ 0.5; i0=(int)x; i1=i0+1;
if (y<0.5) y=0.5; if (y>N+0.5) y=N+ 0.5; j0=(int)y; j1=j0+1;
s1 = x-i0; s0 = 1-s1; t1 = y-j0; t0 = 1-t1;

[b]

d[IX(i,j)] = s0*(t0*d0[IX(i0,j0)]+t1*d 0[IX(i0,j1)])+
s1*(t0*d0[IX(i1,j0)]+t1*d0[IX(i1,j1)]);
[/b]

}
}
set_bnd ( N, b, d );
}

(the part in bold is where the linear interpolation takes place, and I don't get what they're doing).