Skip to main content

fisheye2xyz: Fisheye Projection to Cartesian

Wide-angle spherical coordinate transformation

Fisheye projection captures a hemispherical view onto a circular image. This function converts UV coordinates from a fisheye image back to 3D Cartesian coordinates on the unit sphere:

ndc=2uv1\text{ndc} = 2 \cdot \text{uv} - 1 R=ndcx2+ndcy2R = \sqrt{\text{ndc}_x^2 + \text{ndc}_y^2} ϕ=Rπ0.52\phi = R \cdot \pi \cdot 0.52 (xyz)=(ndcxR1cos2(ϕ)cos(ϕ)ndcyR1cos2(ϕ))\begin{pmatrix} x \\ y \\ z \end{pmatrix} = \begin{pmatrix} \frac{\text{ndc}_x}{R} \sqrt{1 - \cos^2(\phi)} \\ \cos(\phi) \\ \frac{\text{ndc}_y}{R} \sqrt{1 - \cos^2(\phi)} \end{pmatrix}

The factor 0.52 controls the field of view mapping, approximating a 180° fisheye lens.

Projection Characteristics

RadiusField of ViewCoverage
R=0R = 00°Center point
R=0.5R = 0.590°\sim 90°Horizon
R=1R = 1180°\sim 180°Full fisheye

Fisheye Direction Mapping

Live Editor
const fragment = () => {
      const dir = fisheye2xyz(uv)
      const color = iTime.sin().mul(dir).add(0.5)
      return vec4(color, 1)
}