0

I have an image that I use to texture a unit sphere. The sphere is then projected to 2D from various angles and saved as image. For the input image, I have some coordinates $(x,y)$ for which I want to get equivalents $(x',y')$ in the output image, as shown in red in the images below.

INPUT IMAGE

OUTPUT IMAGE

However, I got stuck after transforming the image coordinates into normalized cartesian coordinates. More specific, from normalized cartesian coordinates I want to obtain the 3d unit sphere coordinates. I found some formulas that should help with this but they don't seem to work:

r = 1
x_3d = r * cos(pi*(y - 0.5)) * cos(pi*2*x) 
y_3d = r * cos(pi*(y - 0.5)) * sin(pi*2*x) 
z_3d = r * sin(pi*(y - 0.5)) 

I also tried this (with $R = 1$ and $S = 1$) and that with $\text{radius} = 1$ and $\rho = 1$ but don't seem right either.

What is the right equation for it?

For 3d to 2d projection I plan to use 3D projection on a 2D plane ( weak maths ressources ).

Is there an easier way of obtaining the output coordinates? Thank you.

camar
  • 1
  • Cartographers have invented many, many different ways of mapping between a planar surface and a spherical surface. However, no such transformation exists that does not distort the image in some way or another. The various methods attempt to minimize different aspects of that distortion. You have not made clear here what you are trying to accomplish with this mapping, so we have no way of knowing which transformation would be best in your case. You could at least start by telling what doesn't "seem to work" and what doesn't "seem right either". – Paul Sinclair Sep 04 '19 at 00:38
  • When transforming from 2d to 3d unit sphere coordinates (centered in 0,0,0) I would expect to have the 2d points mapped as it follows:

    (0,0) -> (0,0,1); (0,1) -> (0,1,0); (0,-1) -> (0,-1,0); (-1,0) -> (0,0,-1); (1,0) -> (0,0,-1);

    None of the formulas I've tried does it.

    – camar Sep 04 '19 at 06:38
  • Okay - what do the points $(\pm1, 0), (0, \pm1)$ correspond to in your input image? are they the mid points of the various boundary edges? Are you not mapping anything to the backside of your sphere? What about the point $(1,1)$ - where do want it to map to? – Paul Sinclair Sep 04 '19 at 16:11
  • The points are the boundaries of the texture (I mapped the initial image to [-1,1] on both axes). From these points I want to obtain the 3D coordinates of the texture applied on a sphere of radius 1 centered in (0,0,0). (1,1) should map to (0,1,0). Similarly: (-1,-1) -> (0,-1,0); (1,-1) -> (0,-1, 0); (-1, 1) -> (0, 1, 0); – camar Sep 04 '19 at 20:48

1 Answers1

1

What you are describing is Mercator Projection.

You wrap your flat image around the sphere as a cylinder with a vertical axis (any axis will do, but you might as well rotate it so the axis is vertical). Then everything projects onto the sphere horizontally towards the axis.

This is easiest to express in cylindrical, not spherical, coordinates. Since you are using $y$ as your vertical axis ($z$ is far more common, but it isn't necessary), cylindrical coordinates have the form $(r, \theta, y)$ with $r \ge 0$ and $-\pi < \theta \le \pi$ and correspond to rectangular (i.e., Cartesian) coordinates by $$(r, \theta, y)_{C} = (r\sin \theta, y, r\cos\theta)_R\\(x, y, z)_R = \left(\sqrt{x^2 + z^2}, \operatorname{atan2}(z, x), y\right)_C$$

If $\phi$ is the angle the point makes with the origin and the horizontal plane $y = 0$, positive when $y > 0$, then the relationship between cylindrical and spherical coordinates $(\rho, \theta, \phi)$ is $$(r, \theta, y)_C = \left(\sqrt{r^2 + y^2}, \theta,\tan^{-1}\left(\frac yr\right)\right)_S\\(\rho, \theta, \phi)_S = (\rho\cos\phi, \theta, \rho\sin\phi)_C$$

Calling your image coordinates $(u,v)$ with $-1\le u, v \le 1$, the coordinate $v$ maps directly to $y$, while $\theta = \pi u$. The radial coordinate is found from the equation of the unit sphere: $r^2 + y^2 = 1$.

So the mapping is: $$\begin{align}(u, v) \mapsto& \ \left(\sqrt{1-v^2}, \pi u, v\right)_C\\=&\ \left(\sqrt{1-v^2}\sin\pi u, v, \sqrt{1-v^2}\cos\pi u\right)_R\\=&\ \left(1, \pi u, \sin^{-1}v\right)_S\end{align}$$

If your plan is to then parallel project the sphere onto the plane (much as one would see it if viewing from a long distance away on the $z$ axis), then the easiest form to use is rectangular coordinates, as you can just drop the $z$ coordinate for the parallel projection:

$$(u, v) \mapsto \left(\sqrt{1-v^2}\sin\pi u, v, \sqrt{1-v^2}\cos\pi u\right)_R \mapsto \left(\sqrt{1-v^2}\sin\pi u, v\right)$$ Though you will need to restrict to $-\frac 12 \le u \le \frac 12$ to get only the front side of the sphere.

Paul Sinclair
  • 45,932