Linear Interpolation (lerp)
Method: point.lerp(that, t)
Parameters:
that— the end pointt— a number in the range \([0, 1]\)
Returns: Point
Description
Linear interpolation (lerp) finds the point that lies a fractional distance
\(t\) of the way from this to that along the straight line
between them:
where \(A\) is this and \(B\) is that.
Evaluating the formula at the boundary values and midpoint:
t |
Result |
|---|---|
0 |
\(A\) — the start point |
0.5 |
Midpoint between \(A\) and \(B\) |
1 |
\(B\) — the end point |
Values of \(t\) outside \([0, 1]\) extrapolate beyond the segment.
Relationship to midPoint
The built-in midPoint() method is a special case of lerp with \(t = 0.5\):
Implementation
lerp(that, t) {
return new Point(
this.x + (that.x - this.x) * t,
this.y + (that.y - this.y) * t,
);
}
Usage in Design
lerp is used whenever a point at a known fraction along a segment is needed
— for example, generating intermediate sample points along a line or polyline
segment for snap calculations, or computing a position part-way between two
geometry points during drawing operations.