Skip to content

NetFabric/NetFabric.Numerics / .agents/skills/interpolation-on-manifolds

interpolation-on-manifolds

Verified

Abstract math for interpolating angles, vectors, and quaternions on curved manifolds. USE FOR: implementing Lerp (linear interpolation) for vectors; Nlerp (normalized lerp) for directions; Slerp (spherical linear interpolation) for quaternions and unit vectors; shortest-path sign flip when dot product is negative; choosing between Lerp/Nlerp/Slerp; angular lerp with wrap-around. DO NOT USE FOR: quaternion arithmetic (use quaternion-algebra); rotation representation conversions (use 3d-rotation-theory); angle unit conversions (use angles-and-circular-arithmetic).

FileKindSize
SKILL.mdskill md2.3 KB
references/formulas.mdmarkdown2.0 KB
references/numerical-stability.mdmarkdown1.9 KB
---
name: interpolation-on-manifolds
description: "Abstract math for interpolating angles, vectors, and quaternions on curved manifolds. USE FOR: implementing Lerp (linear interpolation) for vectors; Nlerp (normalized lerp) for directions; Slerp (spherical linear interpolation) for quaternions and unit vectors; shortest-path sign flip when dot product is negative; choosing between Lerp/Nlerp/Slerp; angular lerp with wrap-around. DO NOT USE FOR: quaternion arithmetic (use quaternion-algebra); rotation representation conversions (use 3d-rotation-theory); angle unit conversions (use angles-and-circular-arithmetic)."
---

# Interpolation on Manifolds

## Lerp (Linear Interpolation)

`lerp(a, b, t) = (1−t)·a + t·b`  Result NOT on unit sphere; constant Euclidean velocity.

## Nlerp (Normalized Lerp)

`nlerp(a, b, t) = normalize(lerp(a, b, t))`  Cheaper than Slerp; breaks down at antipodal inputs.

## Slerp (Spherical Linear Interpolation)

Great-circle arc at constant angular velocity:

```
Ω = arccos(a · b)
slerp(a, b, t) = sin((1−t)Ω)/sin(Ω) · a  +  sin(tΩ)/sin(Ω) · b
```

Fall back to Lerp when Ω ≈ 0. Undefined for antipodal inputs (Ω = π).

## Shortest-Path Flip

For quaternions, **q** and **−q** represent the same rotation.
If `a · b < 0`, interpolation takes the long path (> 180°). Fix:

```
if (a · b < 0):  b = −b    (before calling slerp/nlerp)
```

## Which to Use

| Situation | Method | Reason |
|-----------|--------|--------|
| Arbitrary vectors in ℝⁿ | Lerp | Correct; no manifold curvature |
| Unit vectors (approximate) | Nlerp | Fast; adequate for small angles |
| Unit quaternions (smooth) | Slerp | Constant angular velocity |
| Unit vectors (exact) | Slerp | Correct geodesic arc |
| Angles with wrapping | Angular lerp | Handles 350°↔10° via shortest arc |

## Angular Lerp (Wrap-Aware)

```
delta = reduce(b − a, Full)          // shortest signed difference ∈ [−Full/2, Full/2)
result = a + t · delta
```

This ensures the interpolation takes the short way around.

## Reference Files

| File | Load When |
|------|-----------|
| [references/formulas.md](references/formulas.md) | Slerp derivation, degenerate cases, angle lerp proof |
| [references/numerical-stability.md](references/numerical-stability.md) | Near-identical inputs, antipodal inputs, sin(Ω)→0 handling |
planning-and-task-breakdownaddyosmani/agent-skillsBreaks work into ordered tasks. Use when you have a spec or clear requirements and need to break work into implementable tasks. Use when a task feels too large to start, when you need to estimate scope, or when parallel work is possible.Stars: 119kUpdated Claude CodeCodexVerifiedInstall
screenpipethedotmack/claude-memSearch screen and audio history recorded by Screenpipe and optionally save selected context into claude-mem. Use when the user asks to recall desktop activity, a meeting, or something seen in another app through Screenpipe.Stars: 118kUpdated Claude CodeCodexVerifiedInstall
contact-widgetnexu-io/open-designSelf-contained floating chat widget with welcome screen, social links, meeting button, and message input. Single HTML file, zero dependencies.Stars: 108kUpdated Claude CodeCodexVerifiedInstall
meeting-notesnexu-io/open-designMeeting notes page — title bar with attendees, agenda checklist, decisions block, action items table with owners + dates, and a "next meeting" footer. Use when the brief mentions "meeting notes", "minutes", "1:1 notes", "all-hands recap", or "会议纪要".Stars: 108kUpdated Claude CodeCodexVerifiedInstall