mpetroff / pannellum

Pannellum is a lightweight, free, and open source panorama viewer for the web.
https://pannellum.org/
MIT License
4.15k stars 710 forks source link

explanation of the formula in "Pannellum Equirectangular Projection Reference" #1180

Closed zeleamaaa closed 8 months ago

zeleamaaa commented 8 months ago

hello Matthew, is there an explanation of the formula in the document "Pannellum Equirectangular Projection Reference" in the doc folder?

mpetroff commented 8 months ago

It's based on the pinhole camera model, viewing the unit sphere.

Equation (1) is the mapping from spherical coordinates to Cartesian coordinates assuming the horizon is level, equation (2) is the rotation matrix that pitches the camera view up and down, and equation (3) is the result of applying the rotation matrix to the Cartesian coordinates. Equation (4) uses the pinhole camera model to map the coordinates to a 2D image plane, i.e., the film / image sensor of the virtual camera, and equations (5) and (6) are algebraic simplifications, which give image plane coordinates that result from a set of spherical coordinates. Solving the system of equations for the spherical coordinates results in equations (7) and (8), which inverts the projection; this gives the spherical coordinates as a function of image plane position, which is what's needed for rendering a view in the panorama. Finally, equations (9) and (10) follow from the definition of the equirectangular projection and map the spherical coordinates from equations (9) and (10) onto the input panorama image.

Pannellum uses equations (7) and (8), combined with (9) and (10), to directly display equirectangular panoramas with a fragment shader. This is mathematically exact and produces better results than mapping the image onto a geometric mesh approximation of a sphere, which is a technique used in many other panorama viewers.

zeleamaaa commented 8 months ago

thank you very much for the explanation it was very helpful