# Spherical projection problem

This topic is 2264 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I am attempting to write code to take a rectangular, orthographic image of a planet and draw it as a sphere.

My code attempts to iterate through every pixel on the destination and determine A) whether it is part of the planet or not, and B) if so, which pixel to copy the color from off of the source image.

Here is the C++ pseudo-code. Note that pSrcData and pDestData are both arrays of uint32 ABGR color values, ordered from the top left corner and top to bottom, just like text on a page.

void DrawPlanet( uint32* pSrcData,uint32 srcWidth, uint32 srcHeight, uint32 pDestData, uint32 destWidth, uint32 destHeight ) { for ( uint32 iy = 0; iy &lt; destHeight; ++iy ) { for ( uint32 ix = 0; ix &lt; destWidth; ++ix ) { int destIndex = ix + ( destWidth * iy ); if ( PointIsOnPlanet( ix, iy, destWidth, destHeight ) == false ) { pDestData[ destIndex ] = 0; } else { int srcIndex = CalculateSourceIndex( ix, iy, destWidth, destHeight, srcWidth, srcHeight ); pDestData[ destIndex ] = pSrcData[ srcIndex ]; } } } }

What should CalculateSourceIndex() look like? I.e. assuming we are not (yet) attempting to make the sphere rotate, and it's never turned at an angle, how would you determine which pixel on the source image to use for any given pixel of the spherical projection image?

##### Share on other sites
First, take the ray that goes from your eye to the pixel and find the first intersection with the sphere. Then I am sure you can find formulas to convert standard Euclidean coordinates to spherical coordinates in about 10 seconds of searching the web. Or you can do it yourself: Computing the latitude is easy because it only depends on y, and the longitude is atan2(z,x) or something of that sort.

1. 1
2. 2
3. 3
4. 4
Rutin
17
5. 5

• 11
• 21
• 12
• 9
• 11
• ### Forum Statistics

• Total Topics
631403
• Total Posts
2999878
×