Numbers
by Lea Rosema
In this chapter, we'll regard numbers as 1D vectors. This way, we can reuse the knowledge to abstract things to the second and third dimension.
The length of a number
anchorabs(x)
Lengths are always positive, so the length of a number is the absolute value of the number.
- the number
1
has a length of1
. - the number
-2
has a length of2
.
The direction of a number
anchorsign(x)
There are two directions when moving on a number scale. Left (-1
) and right (1
).
The formular for getting the direction of the number is x / abs(x)
. In the world of
vectors, this would be called "normalized" vector.
- the direction of the number
5
is1
- the direction of the number
-2
is-1
- the direction of
0
is not defined
The distance between two numbers
anchorabs(b - a)
The distance between two numbers can be calculated by subtracting the numbers and measuring the length between the two.
- The distance between
-1
and1
is2
Interpolation between numbers
anchorLinear Interpolation
anchorLinear interpolation is used to transition between 2 values.
The function for interpolating between 2 values looks like this, taking 2 values a
and b
and a third parameter x = [0..1]
.
mix(a, b, x) = a * x + b * (1 - x)