Floating point interpolation

**Floating point interpolation** is a means of interpolating one point into another smoothly even if the destination were to suddenly move in unpredictable ways. It is called "floating" because the points are floating about in space and are not rigidly attached to the number line as smoothstep is.

## Usage

The function comes in three variants for 1D, 2D, and 3D, each having a set of variables for each axis. In each variant, the first point, the location, has some velocity, and it accelerates toward the second point, the destination.

### 1D

```
nexus:generic/interpolation/floating_point/1d

```

#### Input

 `#interpolation_acceleration nexus.value` | Acceleration strength of velocity of current point in the direction of the destination.

#### Output

 `#interpolation_velocity nexus.value` | The velocity of the current point is modified just as the location.
It is stored for later use to guarantee the point moves around smoothly.

### 2D

```
nexus:generic/interpolation/floating_point/2d

```

#### Input

 `#interpolation_acceleration nexus.value` | Acceleration strength of velocity of current point in the direction of the destination.
Unlike the other parameters, acceleration only has one value since the motion vector
 `#scale_factor nexus.value` | A value used to temporarily scale down the vector when it computes the length to avoid integer overflows.

#### Output

 `#interpolation_velocity_x nexus.value``#interpolation_velocity_y nexus.value` | The velocity of the current point is modified just as the location.
It is stored for later use to guarantee the point moves around smoothly.

### 3D

```
nexus:generic/interpolation/floating_point/3d

```

#### Input

`#interpolation_location_z nexus.value`
 `#interpolation_destination_x nexus.value``#interpolation_destination_y nexus.value`
`#interpolation_destination_z nexus.value`
 `#interpolation_velocity_x nexus.value``#interpolation_velocity_y nexus.value`
`#interpolation_velocity_z nexus.value`
 `#interpolation_acceleration nexus.value` | Acceleration strength of velocity of current point in the direction of the destination.
Unlike the other parameters, acceleration only has one value since the motion vector
 `#scale_factor nexus.value` | A value used to temporarily scale down the vector when it computes the length to avoid integer overflows.

#### Output

`#interpolation_location_z nexus.value`
 `#interpolation_velocity_x nexus.value``#interpolation_velocity_y nexus.value`
`#interpolation_velocity_z nexus.value`
It is stored for later use to guarantee the point moves around smoothly.

## How it works

In the 1-dimensional variant, the first point accelerates toward the second point by having the acceleration value added to or subtracted from the velocity depending on if the destination value is greater than or less than the current location value. If it is greater, the acceleration is added to the velocity. If it is lesser, the acceleration is subtracted from the velocity. Afterwards, the velocity is multiplied by a coefficient to prevent overshooting. The coefficient is computed with the formula:

d

d

v

where *d* is the distance between the two points and *v* is the current velocity of the point. After the velocity is scaled, the velocity is added to the current location, and both values are returned for storage.

The 2-dimensional and 3-dimensional variants add the extra complication of a dynamic direction. Instead of merely adding the acceleration to the velocity along each axis, it is added as a scaled unit vector pointing directly toward the destination point. The coefficient is computed using the absolute value of the distance and velocity. Because of the use of vector length, it uses the square root and are thus more expensive than the 1-dimensional variant, and often use a scale factor to avoid integer overflows with larger values.

## See also

* Generic functions
* Entity rotation