Representing a view of a 3D sphere as a 2D circle?

Fillipuster

New member
Joined
Oct 11, 2018
Messages
2
Hey everyone, new guy here.

I'm trying to solve a mathematical problem for a computer-science related rendering problem.

My desired result is a 2D "image" representation of a view of a 3D sphere. I suppose you could call it a kind of projection, although not the entire sphere is supposed to be shown.

So, imagine looking at a sphere (like the moon). What you'd see is essentially a flat image - a circle. That is what I am trying to achieve.

A simple image representation of the problem follows:
SphereProblem.jpg

As mentioned, this is a computer science problem which is a result of having little processing power - and thus not being able to simulate a 3D scene with a sphere and a camera. So, my aim is a simple circle image.

My inputs in this situation would be the rotation of the sphere (as Euler angles and/or a quaternion), and some sort of image map for a sphere, as exemplified by this texture for artificial horizon for an airplane:

ivWNhX2.png


As you might be guessing, I am trying to essentially show a part of the image above, based on the imagined rotation of a sphere with said image projected on to it.

Excuse my bad explanations here. This problem is somewhat difficult for me to grasp/explain.

I was hoping some kind soul from FreeMathHelp could be of help here, be it anything from detailed explanations to simply pointing me in the right direction.

I'm more than open to all kinds of possible solutions and/or alternative strategies. Please do not hesitate to ask for more information or elaboration.

-FP
 
It does seem to be a problem of map projection (EDIT: which means mapping points from the surface of a 3D sphere onto a 2D surface of some shape).

I'm not sure what language you use.

Python has a toolkit called basemap that lets you create certain map projections. It's meant for plotting Earth's surface, but you can adapt it show data on an arbitrary sphere (I have used it for displaying astronomical data on the Celestial sphere before).

https://matplotlib.org/basemap/

Some of the map projections do produce circular maps, like the Orthographic, Near-Sided Perspective, and Geostationary ones listed here:

https://matplotlib.org/basemap/users/mapsetup.html

Basemap also lets you plot data over your map, including image data using imshow, as listed here:

https://matplotlib.org/basemap/api/basemap_api.html#mpl_toolkits.basemap.Basemap.imshow

To make this work, you would have to assign (map) a set of coordinates on the sphere (latitude and longitude) to every pixel in your image (after reading in the image as a 2D array).

It shouldn't be difficult to figure out the mapping, as your graphic is literally a spherical coordinate grid (local horizon coordinates) in which the two spherical angles are azimuth (compass direction from 0 to 360 degrees) and elevation (from +90 to - 90 degrees).

Azimuth is the longitude-like coordinate. You may need to convert it to a -180 to +180 ranging quantity to get basemap to like it as a longitude.

Elevation is the latitude-like coordinate.

Edit: Obviously the airplane horizon graphic is incomplete (because it's in a Cartesian projection). But as long as you don't pick basemap projection that actually shows the poles of the sphere, you should be okay.

You might even consider ditching the graphic and just using basemap's built-in coordinate grid, if that has a satisfactory appearance for your application.
 
Last edited:
It does seem to be a problem of map projection (EDIT: which means mapping points from the surface of a 3D sphere onto a 2D surface of some shape).

...

To make this work, you would have to assign (map) a set of coordinates on the sphere (latitude and longitude) to every pixel in your image (after reading in the image as a 2D array).

...

Thanks a lot for the reply @j-astron! Python should work for what I'm doing, and libraries are always nice.

I have to ask though: Regarding the array of coordinates for mapping between the spherical representation and the final image (as I understand it); wouldn't mapping using a series of coordinates diminish precision? Or does basemap simply use them as references to build a more detailed conversion? For this project I need the final product to be very precise.

Thanks again :)
 
Thanks a lot for the reply @j-astron! Python should work for what I'm doing, and libraries are always nice.

I have to ask though: Regarding the array of coordinates for mapping between the spherical representation and the final image (as I understand it); wouldn't mapping using a series of coordinates diminish precision? Or does basemap simply use them as references to build a more detailed conversion? For this project I need the final product to be very precise.

Thanks again :)

Hey @Fillipuster:

Can you explain what you mean by "precision?" Any raster-graphic is going to have finite precision, because it has pixels of finite size. Are you saying that you want the compass/horizon HUD graphic to be in vector graphics format? I'm not exactly sure how to do that. An equivalent would be that you could get basemap to draw a coordinate grid on your map for you, rather than mapping an external graphic onto the sphere and then projecting it onto the map. If you do that, then you can scale your output figure using arbitrary dpi and it will look fine. If you still want to use an external graphic, your only option is to use as high-resolution of a graphic as possible, so that you have more pixels of smaller size (in terms of their area on the sphere).
 
Top