Skip to main content

equirect2xyz: Equirectangular to Cartesian Conversion

Spherical coordinate transformation

The equirectangular projection maps a spherical surface onto a rectangular plane. This function converts UV coordinates (u,v)[0,1]2(u, v) \in [0,1]^2 back to 3D Cartesian coordinates on the unit sphere:

ϕ=πvπ\phi = \pi - v \cdot \pi θ=u2π\theta = u \cdot 2\pi (xyz)=(cos(θ)1cos2(ϕ)cos(ϕ)sin(θ)1cos2(ϕ))\begin{pmatrix} x \\ y \\ z \end{pmatrix} = \begin{pmatrix} \cos(\theta) \sqrt{1 - \cos^2(\phi)} \\ \cos(\phi) \\ \sin(\theta) \sqrt{1 - \cos^2(\phi)} \end{pmatrix}

Where ϕ\phi represents elevation from the equator and θ\theta represents azimuth around the sphere.

Coordinate System Mapping

UV InputAngle RangeDescription
u=0u = 0θ=0\theta = 0Front center
u=0.5u = 0.5θ=π\theta = \piBack center
v=0v = 0ϕ=π\phi = \piSouth pole (bottom)
v=0.5v = 0.5ϕ=π/2\phi = \pi/2Equator (middle)
v=1v = 1ϕ=0\phi = 0North pole (top)

Directional Visualization

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