Intro

We need to wrap a 2D image with normalized UV coordinates on a unit sphere. How can we do that?


1. $v$

  • Let's start with $v$ first because it's easier.
  • $v$ is 0 at the bottom of the picture, and 1 at the top.
  • Equivalently, when mapping, 0 becomes the bottom of the sphere, and 1 becomes the top of the sphere.
  • Conveniently, we can just say $v$ is the vertical coordinate of the sphere.
  • That would normally just be $z$, but we use a special coordinate system for the RT where $y$ is up, so it's just $y$ instead.
  • We can model this was an angle $\phi$ that grows from the $-y$ axis up to the $+y$ axis, meaning $0 \le \phi \le \pi$.
  • Since this is a unit sphere (radius = 1), We can pick a random point on the sphere's surface, and create a triangle where the hypotenuse's length is 1 (it's the radius), the radius makes an angle $\phi$ with the $-y$ axis, and the adjacent side to $\phi$ is just the $y$ coordinate of that point.
  • From that triangle:

$$y = -\cos\phi$$

  • Mapping $v$ to $\phi$ is trivial, since it's equivalent to normalizing $\phi$:

$$v = \frac{\phi}{\pi}$$

2. $u$

  • $u$ is 0 on the left of the image, and 1 is on the right.
  • Equivalently, when mapping, 0 is on the left of the sphere, and 1 is on the right.
  • The question is: where even are left and right?
  • We already decided that in this coordinate system, up is $y$, forwards is $-z$, and we defined it as a right handed coordinate system.
  • So, on your right hand, define your thumb as the $y$ axis, your index as the $z$ axis, and middle finger as the $x$-axis.
  • With this orientation, left is the $-x$ axis.

NOTE: any order works as long as thumb $\times$ index $=$ middle. In our case, $y \times z = x$ so we're good.

  • So $u=0$ is at the negative side of the $x$-axis, and $u = 1$ is at the positive side.
  • But in what direction does $u$ grow? Well, we need $u=0.25$ to be the back ($z$), while $u=0.75$ becomes the front ($-z$), so it rotates like this:

$$-x \rightarrow z \rightarrow x \rightarrow -z \rightarrow -x$$

  • So we need an angle which is $0$ at the negative $x$-axis, $\dfrac{\pi}{2}$ on the $z$ axis, etc.

  • So it grows from $-x$ counterclockwise (remember: $-x$ is left).

  • Let's call that angle $\theta$.

  • From here, we can deduce $x$ and $z$ in terms of $r$ and $\theta$, then use that to get them in terms of $\phi$ and $\theta$.

  • Draw a 2D graph with $-x$ on the left and $-z$ up. That's the right orientation.

  • $\theta$ grows counter counterclockwise starting at $\theta = 0$ at $-x$ axis.

  • $r$ is the distance from the origin.

  • So for some point on the bottom-left quadrant, then draw a triangle from it.

  • You'll be able to deduce this:

$$\cos\theta = \frac{\text{adjacent}}{r}$$ $$\text{adjacent} = r\cos\theta$$

  • Now, since we are at the negative side of the $x$-axis, the length of the opposite side is not the $x$ coordinate, but the negative of the $x$ coordinate.
  • So:

$$x = -r\cos\theta$$

  • The procedure is similar for $z$, but without needing to flip the sign:

$$z = r\sin\theta$$

  • We know that $r$ is fixed for a fixed $\phi$. It's the same as with spherical coordinates.
  • To deduce the relationship from scratch, just project $\rho$ (distance from the origin to any point on the sphere, which is just $1$ since we're dealing with a unit sphere) on the $xy$-plane. This projection is just $r$.
  • Also remember how $\phi$ is the angle from the $-y$ axis up (where $y$-axis looks up).
  • This forms a triangle which you can use to deduce this:

$$r = \sin\phi$$

  • Now substitute in the previous equations for $x$ and $z$:

$$x = -\sin\phi\cos\theta$$ $$z = \sin\phi\sin\theta$$

  • And we're done. We have $x$ and $z$ in terms of $\phi$ and $\theta$.

  • Mapping $u$ to $\theta$ is also trivial, as $u$ is just the normalization of $\theta$:

$$u = \frac{\theta}{2\pi}$$

Conclusion

$$x = -\sin\phi\cos\theta$$ $$y = -\cos\phi$$ $$z = \sin\phi\sin\theta$$

$$u = \frac{\theta}{2\pi}$$ $$v = \frac{\phi}{\pi}$$


$\phi$ and $\theta$ in Terms of $x$, $y$, and $z$

Someday... will also add diagrams later.