Skip to content

NetFabric/NetFabric.Numerics / .agents/skills/coordinate-system-conversions

coordinate-system-conversions

Verified

Abstract math for converting between 2D and 3D coordinate systems. USE FOR: Cartesian to/from polar (r, θ); Cartesian to/from spherical (r, azimuth, polar/colatitude); azimuth vs. elevation vs. colatitude conventions; canonical range enforcement after conversion; precision near the origin and poles; choosing azimuth reference direction. DO NOT USE FOR: angle unit conversions (use angles-and-circular-arithmetic); geodetic (lat/lon) coordinates (use geodetic-coordinate-bounds); rotation representations (use 3d-rotation-theory).

FileKindSize
SKILL.mdskill md2.5 KB
references/formulas.mdmarkdown2.1 KB
references/numerical-stability.mdmarkdown1.9 KB

references/formulas.md

View on GitHub
# Coordinate System Conversions — Formulas

## Polar: Derivation

Point (x, y) in Cartesian ≡ point at distance r from origin at angle θ from +x axis:
```
x = r cos θ,  y = r sin θ    (unit circle definition)
r = √(x²+y²)                  (distance from origin)
θ = atan2(y, x)               (four-quadrant angle)
```

## Spherical: Full Derivation

Starting from the unit sphere and projecting:
```
z = r cos θ                        (height = radius × cos(polar angle))
x = r sin θ cos φ                  (horizontal = projected radius × cos(azimuth))
y = r sin θ sin φ                  (horizontal = projected radius × sin(azimuth))
```

Inverse:
```
r = √(x²+y²+z²)
θ = arccos(z/r)                    (polar angle from z; undefined at r=0)
φ = atan2(y, x)                    (azimuth; undefined at x=y=0)
```

Intermediate: `ρ = √(x²+y²)` (cylindrical radius), so `φ = atan2(y, x)` and `θ = atan2(ρ, z)`.

## Canonical Range Enforcement

After conversion, angles may need reduction:

| Angle | Canonical range | Method |
|-------|----------------|--------|
| 2D azimuth φ | [0, 2π) or (−π, π] | floor-based reduction or atan2 sign |
| Spherical azimuth φ | [0, 2π) | reduction |
| Spherical polar θ | [0, π] | arccos always gives this; no reduction needed |

## Differential Area Element

Spherical: `dA = r² sin θ dθ dφ`  — the sin θ factor is why area vanishes at the poles.

Polar: `dA = r dr dθ`

## Relation: Spherical ↔ Geographic

Geographic uses elevation (latitude) measured from equatorial plane, not from z-axis:
```
lat = π/2 − θ         (elevation = 90° − colatitude)
lon = φ               (same azimuth)
```

So `θ = 0` (north pole) corresponds to `lat = 90°`, and `θ = π` (south pole) to `lat = −90°`.

## Round-Trip Property

Spherical → Cartesian → Spherical recovers the original angles only if:
- r > 0 (not at origin)
- The azimuth is not at a pole (θ ≠ 0 and θ ≠ π)
- The reduced canonical form is compared (angles modulo 2π)

At poles: any azimuth maps to the same point, so round-trip recovers a canonical azimuth (typically 0), not the original.
slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack."Stars: 198kUpdated Claude CodeCodexVerifiedInstall
ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read.Stars: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report.Stars: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt.Stars: 194kUpdated Claude CodeCodexVerifiedInstall