Find the rate at which distances decrease in stereographic projection

172 Views Asked by At

I want to map a 3D space onto the inside's surface of a sphere.

The 3D space is represented by points (x,y,z) where the z axis is the height.

The first thing I did was to use the following equation to map a 2d point on the surface of the (x;y) plane onto a 3D point (x,y,z) placed on the surface of the unit sphere: $(x,y)=(\frac{2x}{1+x^2+y^2},\frac{2y}{1+x^2+y^2},\frac{-1+x^2+y^2}{1+x^2+y^2})$ (thanks to this wiki page about Stereographic Projection).

If I create an infinite ground at z = 0, the projection creates a perfect sphere of radius 1 centered at the origin with a single hole at the north pole.

But for now this equation doesn't take the original height of the point. I'm working in video games. I have a flat world with 3d objects on it represented by vertices (3d points).

I want to map this world onto the inside of a sphere. At ground level where z = 0, using the stereographic projection works fine. But this projection doesn't take into account the height of the objects. The higher an object is on the plane, the higher it should be on the projection (thus closer to the center of the projection's sphere)

In order to know how I should integrate the z axis into this formula, I tried to compare it with the current projection. In the current projection, everything near the origin of the plane gets a really low amount of distorsion. It gets worse the higher up you go on the sphere (equivalent to getting further and further away on the plane) where distances get squeezed. For example, a plane of size 1 is relatively still of size 1 on the projection if it's near the origin.

So I would like that if there is a cube of size 1 near the origin, it gets the same amount of deformation as the distances do and have a height of 1 too. But I don't really know how to do that. How can I calculate the rate at which distances get shorter the further you go in the projection ?

Also, I think that there are 2 parameters to take into account: the first one is the distance at which the vertex is from the origin, which will decrease its height on the projection, and the second one is the actual z position of the vertex because there will also be a vertical distorsion (a tower of length 1 and infinite (vertical) size at the origin will still have a length of 1 at z = 0, but will have a really smaller length as it's closer to the sphere's center)

Here are some screenshots that illustrate this problem better. In both screenshots, the camera is inside of the sphere at (0,0,-1). In the first screenshot you can see that the red cubes are completely stretched and doesn't look like cube anymore because the z value is wrongly integrated. This is because they're far from the center of the projection (the hole is because of the render distance. I cannot render an infinite plane, so the sphere is incomplete)

enter image description here

In the second one though, we're looking at an area near the center so they look like regular cubes. This is because in those screens I made that every cube has the same height no matter where they are projected. So it works fine in the center where the cubes have no distorsion, but as the cube gets smaller with the distorsion, their height is still at 1 and it looks like they're getting higher.

enter image description here

I'm a bit stuck so any help is welcome!

1

There are 1 best solutions below

2
On BEST ANSWER

The metric of the sphere in stereographic coordinates is

$$g_{\mu\nu}dx^{\mu}dx^{\nu}=\frac{4}{(1+X^2+Y^2)^2}(dX^2+dY^2)$$

That means that close to the origin $(0,0)$ the cubes should be looking bigger by a factor of 4 approximately. I assume you don't see that because of the camera and finite effects. at larger distances they should be looking smaller and smaller, which agrees qualitatively with the screenshots. The above metric indicates that, as a quick fix, the height $dz$ of small cubes far from the center should be downsized by a factor of $\frac{2}{x^2+y^2+1}$, proportionally to their sizes $dx$, $dy$ that are scaled down by the same factor to keep their proportions. That should work pretty well if the camera and other viewing distortions are not taken into account.