### 6.1.2 Level sets

The level set method (technique) is a relatively novel introduction to computer graphics, and is most commonly used for generating fluid effects such as splashes.

First of all, what is a level set? It is simply a set of values that collectively define a level or an isovalue, from among a bigger set of values. Eg. out of all the (infinite) points on a plane, all the points on a circle of radius 6 units constitute a level set - these are the points that define a curve that is equidistant (at a distance of 6 units, which is the 'iso' value) from the origin (Fig 6.1.2.1).

`Figure 6.1.2.1 A simple, circular level set.`

### 5.1.1 Linear interpolation

Linear interpolation ("lerp") is one of those fundamental, high-mileage operations in CG - once you get the basic/simple idea, you can use it in a wide variety of situations.

'lerp' can used to interpolate between a pair of scalars and also between two aggregate (bundled) entities such as points and colors.

#### Scalars

Scalar lerp is pretty straightforward: given a quantity (eg. height) and a pair of values A and B for it, we'd like to calculate intermediate values between endpoints A and B, given the relative mix of them. Eg. we expect a 50/50 blend of A and B to result in an interpolated value of `(A+B)/2`, ie. the arithmetic average of A and B. Eg. if A is 6.4 and B is 5.2, the average is `(6.4+5.2)/2` which is 5.8. But what about a 25/75 mix of A and B (25% A and 75% B) or a 73/27 mixture etc.? For the general case that encompasses all these, we use the lerp formula:

`text(lerp)(A,B,f) = (1-f)*A + f*B`

In the above, `f` is a fraction, between 0.0 and 1.0, which specifies the % of B. By definition, `(1-f)` specifies the rest, ie. the contribution of A.

You can see that the 50/50 case, where `f` and `1-f` are both 0.5, leads to the familiar average, ie. `0.5*A + 0.5*B` which is `0.5*(A+B)`. Also, `f` being 0.0 and 1.0 lead to the "book end" cases of the result being `A` and `B` respectively, as you'd expect.

lerp is best visualized as a simple plot between `text(lerp)()` and `f` (Figure 5.1.1.1). You can see that the interpolation between A and B is linear, ie. the intermediates lie on the red straight line that joins A and B. Here is another way of looking at this: equal intervals along `f` lead to (correspond to) equal intervals along the red lerp line. In the diagram, the midpoint of the `f` interval (f=0.5) yields the midpoint of the red lerp segment.

There is nothing that stops `f` from taking on values outside the usual `0..1` range, in which case the result is an extrapolation. Note that such extrapolation can happen on either side, ie. `f<0` as well as `f>1`. Figure 5.1.1.2 depicts extrapolation.

Observe that the lerp formula stated above can also be written as `text(lerp)(A,B,f) = A - f*A + f*B` which reduces to `A + (B-A)*f`. This makes it even easier to see that `f` is the free variable that takes us from A to B, as it varies from 0 to 1.

As a reminder, lerp can be used to interpolate any scalar quantity, including, for instance, temperature, light intensity, etc. Figure 5.1.1.3 shows the radius value interpolated between a pair of circles, at interpolations fractions 0.25, 0.5 and 0.75.

Also, here is a common case - given a frame range `f_s` to `f_e` and a quantity with endpoint values A and B at `f_s` and `f_e` respectively, what is the interpolated value at a given current frame `f_c`? In other words, we need to first invert the lerp operation to obtain a fraction `f` that represents our current frame `f_c` that lies between `f_s` and `f_e`, and use that `f` to interpolate between A and B. See Figure 5.1.1.4.

Inverting lerp is straightforward (this is also a linear operation, and is called 'normalization'):

`f = (f_c-f_s)/(f_e-f_s)`

As a quick check, when `f_c` equals `f_s` in the above formula we get `f=0` (remember, `f` denotes fraction of `f_e`) and likewise when `f_c=f_e` we get `f=1`. We can now use `f` as usual to lerp between A and B, to derive an interpolated value at `f_c`. Like lerp itself, the normalization formula is also quite useful, especially when dealing with frame ranges as was just described.

#### Aggregates ("vectors")

As we just saw, lerp is a useful operation that lets us interpolated values between a pair of scalars. But that is not all.

```* points - param. repr of a pt is eqvt to lerp!
* colors (triplets) - linear and radial ramps [http://www.w3.org/TR/SVG/images/painting/inheritance.svg]
* pixel-blending operation!

* morphing!
* Gouraud
* multi-samp -  show using a ramp and a 2D path
* interp angles OK for vectors (clock), tips NOT OK!- for slerp :)
```