Draft
edit

## What is interpolation?

At its most basic level, interpolation is finding a number between two other numbers.

The basic interpolation formula is: start with one value (a), than add a fraction (factor) of the difference with another value (b).

``````a + factor * (b - a)
``````

Translating the formula into code:

``````def interpolateNumbers(factor, a, b):
return a + factor * (b - a)

print(interpolateNumbers(0.3, 0, 100))
print(interpolateNumbers(0.3, 200, 500))
``````
``````30.0
290.0
``````

Interpolation can be applied to anything that can be represented as numbers: position, dimensions, colors… and glyph shapes too.

## Terminology

masters
Data objects that are used in an interpolation system.
instances
Data objects generated by interpolating the masters.
interpolation factor

A number between `0` and `1`. For example:

• factor is `0.0` → result is identical to the first master
• factor is `1.0` → result is identical to the second master
• factor is `0.5` → result is exactly between the two masters
extrapolation
Interpolation with factors outside the `0``1` range.
axis
The particular change in an object when interpolating from one master to another.

### Extrapolation

Extrapolation is using interpolation to find a number beyond the masters – using a factor that is less than `0` or greater than `1`.

``````print(interpolateNumbers(1.2, 200, 500))
print(interpolateNumbers(-0.2, 200, 500))
``````
``````560.0
140.0
``````

### Interpolating colors

To interpolate between two n-dimensional objects, we simply interpolate each dimension separately.

Here’s an example using `(r,g,b)` tuples representing colors:

``````def interpolateColors(factor, c1, c2):
# unpack color tuples
r1, g1, b1 = c1
r2, g2, b2 = c2
# interpolate each channel separately
r = interpolateNumbers(factor, r1, r2)
g = interpolateNumbers(factor, g1, g2)
b = interpolateNumbers(factor, b1, b2)
# return resulting color
return r, g, b

print(interpolateColors(0.5, (1, 0.1, 0), (1, 0, 1)))
``````
``````(1.0, 0.05, 0.5)
``````

## Interpolation requirements

Interpolation works only if the two data objects being interpolated have the same “topology”:

• the same amount of dimensions
• matching types of dimensions

### Interpolating glyphs

A glyph is described by numbers too: the position of all points, anchors and components, the glyph’s advance width, mark color, etc.

The `RGlyph` object in FontParts has an `.interpolate()` method which takes an interpolation factor and two glyphs as input:

``````glyph.interpolate(factor, glyph1, glyph2)
``````

The interpolation factor can be a tuple of two values, one for each dimension:

``````glyph.interpolate((factorX, factorY), glyph1, glyph2)
``````

The `RFont` and `RKerning` objects also have `.interpolate()` methods.

## Interpolation workflow

Interpolation can be used in different stages of a project:

### Interpolating glyphs

In the design stage, you might want to interpolate a few glyphs only, to see how the result looks like – making quick tests with key glyphs to find the right interpolation factors.

### Interpolating fonts

In the production stage, you can interpolate a whole font, or a series of fonts at once – without using the UI to speed things up.

Proper interpolation between fonts involves interpolating not just the glyphs, but also the kerning and some numerical font info attributes, such as blue zones, OS/2 weight numbers, etc.

## GlyphMath

If two glyphs are compatible, they can also be used in GlyphMath expressions.

GlyphMath uses operator overloading to add basic arithmetic operations to glyph objects: glyphs can be added or subtracted by each other, and can be multiplied or divided by a number.

GlyphMath can be used to create interpolation effects, transplant transformations from one glyph to another and superimpose several effects at once.

## MutatorMath

MutatorMath is a Python library to calculate interpolations between multiple masters in multiple dimensions. It was developed for interpolating data related to fonts, but it can handle any arithmetic object.

## Superpolator

Superpolator is a macOS application for creating font families using multidimensional interpolation. It uses MutatorMath as its interpolation engine, and offers a rich interface for creating and visualizing the interpolation space and the instances.

Last edited on 02/06/2020