Docsity

Linear Interpolation: Estimating Values between Given Points, Study notes of Computer Graphics

Toggle sidebar
bg1
Linear interpolation
‘Real’ functions are rarely given by an explicit formula allowing to evaluate
them anywhere. More frequently, only ‘sample’ values of the function are given
at certain points and, in order to estimate the value at some place which is not a
sample, we need to somehow combine the available information. This is the goal
of interpolation. By doing interpolation one can, for example, build a complete
elevation map of a terrain when only an array of height values is given (this is
what happens in practice: height cannot be measured everywhere; no matter
how you do it, you end up with only finite number of measurements). We used
interpolation to estimate the color over a triangle when colors at vertices are
given, or normals/depths over the triangle from normals/depths at the vertices.
Linear interpolation from vertices of a triangle
(x’,y’)
v0
v1
v2
p0=(x0,y0)
p1=(x1,y1)
p2=(x2,y2)
Figure 1: Linear interpolation from triangle’s vertices: notation.
Here is how the variant of linear interpolation we used works. Let’s say
that we have a triangle as shown in Figure 1. It has vertices p0= (x0, y0),
p1= (x1, y1), p2= (x2, y2). At each vertex we have a value, let’s say that they
are v0,v1and v2. There is exactly one linear function which takes the value of
v0at p0,v1at p1and v2at p2(We can prove that by ’embedding’ our triangle
and the values at vertices in 3D: say that the triangle lies in the groung plane;
lift p0to height v0,p1to height v1and p2to height v2. This yields 3 points in
3-space. Now, find the plane passing through the three points. This plane is
the graph of the linear function we are looking for). Here is how to compute it
algebraically.
We seek a function of the form f(x,y ) = Ax +By +C(A, B, C to be
determined). The requirement that the values at the vertices are v0,v1and v2
leads to three linear equations
Ax0+By0+C=v0
Ax1+By1+C=v1
Ax2+By2+C=v2.
1
pf2

Partial preview of the text

Download Linear Interpolation: Estimating Values between Given Points and more Study notes Computer Graphics in PDF only on Docsity!

Linear interpolation

‘Real’ functions are rarely given by an explicit formula allowing to evaluate them anywhere. More frequently, only ‘sample’ values of the function are given at certain points and, in order to estimate the value at some place which is not a sample, we need to somehow combine the available information. This is the goal of interpolation. By doing interpolation one can, for example, build a complete elevation map of a terrain when only an array of height values is given (this is what happens in practice: height cannot be measured everywhere; no matter how you do it, you end up with only finite number of measurements). We used interpolation to estimate the color over a triangle when colors at vertices are given, or normals/depths over the triangle from normals/depths at the vertices.

Linear interpolation from vertices of a triangle

(x’,y’)

v v

v

p0=(x0,y0)

p1=(x1,y1)

p2=(x2,y2)

Figure 1: Linear interpolation from triangle’s vertices: notation.

Here is how the variant of linear interpolation we used works. Let’s say that we have a triangle as shown in Figure 1. It has vertices p 0 = (x 0 , y 0 ), p 1 = (x 1 , y 1 ), p 2 = (x 2 , y 2 ). At each vertex we have a value, let’s say that they are v 0 , v 1 and v 2. There is exactly one linear function which takes the value of v 0 at p 0 , v 1 at p 1 and v 2 at p 2 (We can prove that by ’embedding’ our triangle and the values at vertices in 3D: say that the triangle lies in the groung plane; lift p 0 to height v 0 , p 1 to height v 1 and p 2 to height v 2. This yields 3 points in 3-space. Now, find the plane passing through the three points. This plane is the graph of the linear function we are looking for). Here is how to compute it algebraically. We seek a function of the form f (x, y) = Ax + By + C (A, B, C to be determined). The requirement that the values at the vertices are v 0 , v 1 and v 2 leads to three linear equations

Ax 0 + By 0 + C = v 0 Ax 1 + By 1 + C = v 1 Ax 2 + By 2 + C = v 2.

We can solve them, obtaining A, B and C. So, for example, to compute the in- terpolated value at the point p′^ = (x′, y′) we need to evaluate f (p′) = f (x′, y′) = A ∗ x′^ + B ∗ y′^ + C.

Alternative approach

p

p

p

p’

t*p0p

u*p0p

0<=t<=

1<=t<=

Figure 2: The second method.

One can also think of linear interpolation in the following way. We want to move from p 0 to p′^ by first moving some amount along the vector from p 0 to p 1 and then by some fraction of the vector from p 0 to p 2 (see Figure 2). This can be algebraically expressed in the following way:

p′^ = p 0 + t ∗ p 0 ~p 1 + u ∗ p 0 ~p 2. (1)

Notice that since we know that p′^ is inside the triangle, t and u have to be nonnegative and need to satisfy t + u ≤ 1. Basically, if either t or u were negative, we would be moving in the wrong direction (either to the left of the edge joining p 0 and p 1 or below the edge from p 0 to p 2 ). If u + t > 1, we would be moving too far (e.g. if 1 < t + u ≤ 2 then we would end up in the triangle complementing ∆p 0 p 1 p 2 to a parallelogram - see the Figure). Now, since we want the interpolated function to be linear over the triangle, its increase along t ∗ p 0 ~p 1 has to be t times the increase over p 0 ~p 1. A similar statement holds for p 0 ~p 2. Therefore, the interpolated value v′^ at p′^ can be computed as

v′^ = v 0 + t ∗ (v 1 − v 0 ) + u ∗ (v 2 − v 0 ).

Of course, we still need to compute t and u. This is easy though: from 1 we have the following equations that can be solved for t and u:

x′^ = x 0 + (x 1 − x 0 )t + (x 2 − x 0 )u y′^ = y 0 + (y 1 − y 0 )t + (y 2 − y 0 )u