---
title: "Quaternion NLerp in C#: blend two rotations"
url: https://recursiveai.org/onemath/cookbook/nlerp-quaternion-rotations/
description: "Blend two quaternion rotations in C# using normalized linear interpolation (NLerp). Take the shortest path and compare angular progress with Slerp."
version: "1.0.0"
---

# Quaternion NLerp in C#: blend two rotations

**OneMath** is a free, open-source deterministic math library for .NET from Recursive AI. MIT or Apache-2.0, no native dependencies.

[NuGet](https://www.nuget.org/packages/RecursiveAI.OneMath) · [GitHub](https://github.com/recursive-ai-oss/onemath-csharp) · [Docs](https://recursiveai.org/onemath/docs/) · [Download example (.zip)](https://recursiveai.org/onemath/cookbook/nlerp-quaternion-rotations/nlerp-quaternion-rotations.zip)

NLerp (normalized linear interpolation) blends unit quaternions along the shortest rotation.

```shell
dotnet add package RecursiveAI.OneMath
```

Requires [.NET 10](https://dotnet.microsoft.com/download/dotnet/10.0) (net10.0); .NET 9 and earlier aren’t supported.

```csharp
using RecursiveAI.OneMath;
var start = QuaternionD.Identity;
var end = new QuaternionD(0, 0, -.8, -.6);
var mid = QuaternionD.NLerp(start, end, .5);
Console.WriteLine($"{mid.Z:F3}, {mid.W:F3}");
```

Unzip [the example](https://recursiveai.org/onemath/cookbook/nlerp-quaternion-rotations/nlerp-quaternion-rotations.zip), then `dotnet run`.

Prints the midpoint’s Z and W components: `0.447, 0.894` with an English locale. X and Y are zero.

## The full program

```csharp
using RecursiveAI.OneMath;

var start = QuaternionD.Identity;
var end = new QuaternionD(0, 0, -.8, -.6);
foreach (double t in new[] { 0, .25, .5, .75, 1 })
{
    var nlerp = QuaternionD.NLerp(start, end, t);
    var slerp = QuaternionD.Slerp(start, end, t);
    double nAngle = AngleDegrees(nlerp);
    double sAngle = AngleDegrees(slerp);
    Console.WriteLine(FormattableString.Invariant(
        $"{t:0.00}: {nAngle:F2}°, {sAngle:F2}°"));
}

static double AngleDegrees(QuaternionD rotation)
{
    var direction = rotation.Rotate(Vector3D.UnitX);
    return Math64.Atan2(direction.Y, direction.X) * 180 / Math.PI;
}
```

```text
0.00: 0.00°, 0.00°
0.25: 25.06°, 26.57°
0.50: 53.13°, 53.13°
0.75: 81.20°, 79.70°
1.00: 106.26°, 106.26°
```

Each row shows `t` followed by the angle from the positive X axis for NLerp, then spherical linear interpolation (Slerp).

The destination has a negative dot product with the start, so NLerp flips its sign before blending. Both signs describe the same rotation. Use unit quaternions for the endpoints and keep `t` between 0 and 1 for an in-between rotation; the method doesn’t clamp `t`.

## Variations

If the angle must advance uniformly as `t` increases, compare Slerp at a quarter of the way. Append this to the snippet at the top:

```csharp
var q = QuaternionD.Slerp(start, end, .25);
Console.WriteLine($"{q.Z:F3}, {q.W:F3}");
```

The extra line prints `0.230, 0.973` with an English locale.

## Related recipes

- [Interpolate quaternion rotations with Slerp](https://recursiveai.org/onemath/cookbook/interpolate-quaternion-with-slerp/)
- [Work with vectors and quaternions](https://recursiveai.org/onemath/cookbook/vector-and-quaternion-math/)

---

## The short answer

For normalized linear interpolation (NLerp), call `QuaternionD.NLerp(start, end, t)` with two unit quaternions and a fraction between 0 and 1. Use `QuaternionF.NLerp` for `float` quaternions. In either case, the result is an orientation, not an angle; the full example rotates a vector to make the difference in angles visible.

## How do you interpolate quaternions along the shortest path?

A unit quaternion and its negation rotate a vector the same way. They have different component values, though, so interpolating components straight to the supplied endpoint can take the long way around. OneMath’s [evaluation-order reference](https://recursiveai.org/onemath/docs/evaluation-order/#quaternions) specifies that NLerp negates the destination first if the dot product is negative. It then blends the four components and normalizes the result back to unit length, up to floating-point rounding. `Lerp` by itself does neither the sign correction nor the normalization.

At `t = 1`, compare the rotation, not the signs of the returned components. In this example the destination uses negative Z and W, but the final interpolated rotation has positive Z and W. If the dot product is exactly zero, the relative rotation is 180° and either direction is equally short. OneMath keeps the supplied destination sign in that tie, so changing that sign can change the intermediate orientation.

## What is the difference between NLerp and Slerp?

The difference is [how the angle changes with `t`](https://gabormakesgames.com/blog_quats_interpolate.html). Spherical linear interpolation (Slerp) advances the angle uniformly with `t`; NLerp blends the components in a straight line before projecting back to unit length. The projected angle doesn’t advance uniformly. Look at the quarter and three-quarter rows: at `t = 0.25`, NLerp has advanced about 25.06° instead of 26.57°. By `t = 0.75`, it has advanced about 81.20° instead of 79.70°. The endpoints and midpoint agree in this example, so testing only halfway won’t reveal the difference.

Choose NLerp for blending where the exact timing of the angle doesn’t matter. Choose Slerp when equal steps in `t` should give equal angle steps, such as turning a camera uniformly over a fixed interval. For nearly identical endpoints, the pinned OneMath Slerp implementation uses normalized interpolation as a close-angle approximation; the [same reference](https://recursiveai.org/onemath/docs/evaluation-order/#quaternions) gives the cutoff.
