Linear interpolation
Linear interpolation is a simple interpolation method widely used in mathematics, computer graphics, and other fields.
If we know the coordinates (x0, y0) and (x1, Y1), we need to obtain the value of X in a straight line in a certain position in the [x0, X1] range. As shown in the figure, we get (y-y0) (x-x0)/(y1-y0) (x1-x0)
Assuming that the values on both sides of the equation are α, this value is the ratio of the interpolation coefficient-distance from x0 to X to distance from x0 to X1. Since the X value is known, we can obtain the α value from the formula.
α = (x-x0)/(x1-x0)
Similarly, α = (y-y0)/(y1-y0)
In this way, it can be represented:
Y = (1-α) y0 + α Y1
Or,
Y = y0 + α (Y1-y0)
In this way, we can directly obtain y through α. In fact, this formula is also true even if X is not between x0 and X1 and α is not between 0 and 1. In this case, this method is called linear interpolation-see external interpolation.
It is known that the process of finding X by Y is the same as that above, but x and y need to be exchanged.
Lerp function (linear interpolation)