Search code examples
algorithmpseudocodeprojectioncubepanoramas

A 360 degree Sphere panorama into Cube panorama transformations algorithm (pseudocode or at least full logic wanted)


So we can take such image from wikipedia alt text And try to map it for future cube or something like cube alt text alt text

And than distort for top and bottom like alt text

Some one may think that doing disturtion only for half and than triing to fill it would work alt text

it would not=( and content aware filling would not help filling that square=(

but it looks bad if you will try to render such cubic panorama.

Another way that I can imagine is to render 3d panorama onto sphere and than somehow take snapshots/projections of it onto cube... but I do not know how to write it down wit simple math operations (idea here is not to use rendering engines but to do it as mathematically as possible)


Solution

  • There's a map projection called the Quadrilateralized Spherical Cube that's used in astrophysics to represent all-sky maps. It has a nice property that the pixels are within a few percent of having equal areas all over the sky, so that geometric distortions are reduced.

    Basically, the celestial globe is projected onto a cube, and each cube face is divided into pixels; but rather than being a rectilinear grid, the row and column boundaries are slightly curved so that each pixel maps to a roughly equally sized area on the sphere.

    The pixel addressing is kind of interesting. Suppose you have a pixel with coordinates X,Y on one of the cube faces. If X has binary representation abcd, and Y is ABCD, then the pixel address on that face has X and Y interleaved: aAbBcCdD. So to rebin the image to larger pixels, all you need to do is shift right 2 bits to get the pixel address at the lower resolution.

    With 32-bit pixel addresses, you can use 3 bits to represent the cube face, and 28 bits to represent the interleaved X and Y coordinates within that face. At this resolution, each pixel covers an area of about 20x20 arcsec, or about a third of a mile square(ish) -- so one could make good use of this as a sort of geographic or celestial coordinate hashing technique.

    To use this, you'd have to implement forward transformations (long, lat) or (RA, dec) to pixel numbers, and inverse transformations going from pixel numbers to (long, lat) or (RA, dec). And of course there are tons of well-known map projections from image coordinates to (long,lat) and back.

    I didn't find any code for this in a few minutes of Googling -- maybe I can dig up some code I wrote about 20 years ago when I worked on the EUVE astrophysics mission, which used this projection for their all-sky survey maps.