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

references/formulas.md

View on GitHub
# Interpolation on Manifolds — Formulas

## Lerp Properties

```
lerp(a, b, 0) = a
lerp(a, b, 1) = b
lerp(a, a, t) = a           (same point)
lerp(a, b, t) = lerp(b, a, 1−t)    (reversible)
```

Extrapolation (t outside [0,1]) is mathematically valid; implementations may choose to clamp.

## Slerp Derivation

On the unit sphere, the geodesic (shortest path) between unit vectors **a** and **b** is the
great-circle arc. Parameterize by arc fraction t ∈ [0,1]:

```
Ω = arccos(a · b)           (total arc angle)

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

This follows from the spherical law of sines applied to the arc.

**Verification**: at t=0: `sin(Ω)/sin(Ω)·a + 0 = a`. At t=1: `0 + sin(Ω)/sin(Ω)·b = b`.

## Slerp Degenerate Cases

| Condition | Ω | Behavior |
|-----------|---|----------|
| a ≈ b | Ω ≈ 0 | sin(Ω) ≈ 0; fall back to lerp(a,b,t) |
| a ≈ −b | Ω ≈ π | Result undefined — infinitely many great circles |

For the antipodal case, choose an arbitrary orthogonal vector to define the interpolation plane.

## Nlerp vs Slerp: Error Bound

The angle error of Nlerp vs Slerp is bounded by:
```
|θ_nlerp − θ_slerp| ≤ C · Ω²
```
where C ≈ 0.125 and Ω is the arc angle. For Ω < 5°, the error is < 0.05° — acceptable for animation.

## Angular Lerp: Shortest-Difference Method

```
delta = b − a
// Reduce delta to (−Full/2, Full/2] — the signed shortest arc
if delta > Full/2:   delta -= Full
if delta < −Full/2:  delta += Full
result = a + t · delta
```

Example (degrees): a=350°, b=10°, t=0.5
- delta = 10 − 350 = −340
- Reduce: −340 + 360 = 20
- result = 350 + 0.5 · 20 = 360° → reduces to 0°  ✓

## Squad (Smooth Quaternion Spline, reference)

For smooth quaternion sequences (not constant velocity but smooth), squad uses:
```
squad(q₀, q₁, s₀, s₁, t) = slerp(slerp(q₀,q₁,t), slerp(s₀,s₁,t), 2t(1−t))
```
where s₀ and s₁ are auxiliary control quaternions computed from neighboring keyframes.
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