- What is interpolation?
- Interpolation requirements
- Interpolation workflow
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))
Interpolation can be applied to anything that can be represented as numbers: position, dimensions, colors… and glyph shapes too.
- Data objects that are used in an interpolation system.
- Data objects generated by interpolating the masters.
- interpolation factor
A number between
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
- factor is
- Interpolation with factors outside the
- The particular change in an object when interpolating from one master to another.
Extrapolation is using interpolation to find a number beyond the masters – using a factor that is less than
0 or greater than
print(interpolateNumbers(1.2, 200, 500)) print(interpolateNumbers(-0.2, 200, 500))
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 works only if the two data objects being interpolated have the same “topology”:
- the same amount of dimensions
- matching types of dimensions
A glyph is described by numbers too: the position of all points, anchors and components, the glyph’s advance width, mark color, etc.
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)
RKerningobjects also have
Interpolation can be used in different stages of a project:
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.
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.
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 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 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.