Notes:Spherical coordinates
This is in reference to this question and not a part of the site, I needed math-markup
Contents
Manifolds
Take the Earth (the planet that we're on) - it's actually (topologically) a sphere, it's a bit bumpy but mainly a sphere, yet to someone standing on it it is rather plane-like. This was actually the subject of some dispute many years ago!
This is the basis for a topological manifold the idea is you have this "blob" but bits of it look like (chunks of) [ilmath]\mathbb{R}^n[/ilmath] if you stay in certain regions. In our case parts of the earth look like planes, so are subsets of [ilmath]\mathbb{R}^2[/ilmath] - we would say the Earth is a topological [ilmath]2[/ilmath]-manifold.
Charts and atlases
A chart should make you think of the explorers of the past, charting the oceans and such. It's a bit of paper that "chart"s a specific area. Bits of paper are bits of a plane.
Many charts make an atlas - an atlas is just a bunch of charts that cover the entire thing we're charting.
Terminology
Let [ilmath]M[/ilmath] be our manifold.
- A chart is a function, [ilmath]\phi:U\rightarrow\mathbb{R}^n[/ilmath] where [ilmath]U[/ilmath] is some portion of our manifold, [ilmath]M[/ilmath], for example here in the UK we have something called ordinance survey maps that take the UK and map it onto a plane with grid-reference coordinates.
- An atlas is a collection of charts, [ilmath]\{\phi_i:U_i\rightarrow\mathbb{R}^n\}_{i\in A} [/ilmath] is how we'd write this. [ilmath]A[/ilmath] is our index for a collection of charts, some set such that if we take some [ilmath]i\in A[/ilmath] (note [ilmath]\in[/ilmath] means "in" - literally, so here I am saying "for some [ilmath]i[/ilmath] in [ilmath]A[/ilmath]") we have a chart [ilmath]\phi_i:U_i\rightarrow\mathbb{R}^n[/ilmath] - for that [ilmath]i\in A[/ilmath] we have a chart, called [ilmath]\phi_i[/ilmath] that takes a chunk of the manifold, [ilmath]U_i[/ilmath] to [ilmath]\mathbb{R}^n[/ilmath].
Going between charts
(see transition map - it has a good picture)
Take two charts, [ilmath]\phi:U\rightarrow\mathbb{R}^n[/ilmath] and [ilmath]\psi:V\rightarrow\mathbb{R}^n[/ilmath] where we have:
- [ilmath]U\cap V\ne\emptyset[/ilmath] ([ilmath]\cap[/ilmath] denotes intersection of sets, [ilmath]x\in A\cap B\iff x\in A\text{ and }x\in B[/ilmath], [ilmath]\emptyset[/ilmath] denotes the empty set, so here we are saying "there are things in both [ilmath]U[/ilmath] and [ilmath]V[/ilmath])
Then for an [ilmath]x\in U\cap V[/ilmath] we have two sets of "coordinates", we have:
- [ilmath]\phi(x)[/ilmath] - which gives us some coordinates according to [ilmath]\phi[/ilmath]
- [ilmath]\psi(x)[/ilmath] - which gives us some coordinates according to [ilmath]\psi[/ilmath]
That is this point [ilmath]x[/ilmath] has differing coordinates, depending on how we view it.
In this case we can define a transition map, [ilmath]t:\mathbb{R}^n\rightarrow\mathbb{R}^n[/ilmath] that takes coordinates in [ilmath]\phi[/ilmath] to their coordinates in [ilmath]\psi[/ilmath]. It is easy to define.
Here's a picture (on the right)
- [ilmath]\text{Im}_\phi(U\cap V)[/ilmath] is all the "image" of [ilmath]U\cap V[/ilmath] under [ilmath]\phi[/ilmath] and is the shaded bit on the bottom left. These are what [ilmath]U\cap V[/ilmath] maps to uder [ilmath]\phi[/ilmath]
To go from [ilmath]\text{Im}_\phi(U\cap V)[/ilmath] to the other chart we must go back to the manifold, via [ilmath]\phi^{-1} [/ilmath] - this is the inverse of [ilmath]\phi[/ilmath].
- If [ilmath]\phi:U\rightarrow\mathbb{R}^n[/ilmath] then [ilmath]\phi^{-1}:\mathbb{R}^n\rightarrow U[/ilmath] where [ilmath]\phi^{-1}(y)=\{\text{all the things such that }\phi(\text{thing})=y\}[/ilmath]
So we take [ilmath]x\in\text{Im}_\phi(U\cap V)[/ilmath] - some point in the [ilmath]\mathbb{R}^n[/ilmath] of our [ilmath]\phi[/ilmath] chart and we:
- Go back onto the manifold, by doing [ilmath]\phi^{-1}(x)[/ilmath] if we call this [ilmath]y[/ilmath] then [ilmath]\phi(y)=x[/ilmath] remember
- We now take [ilmath]\phi^{-1}(x)[/ilmath] (which is on [ilmath]M[/ilmath] remember) to the coordinates in the other chart, [ilmath]\psi[/ilmath]
- By doing [ilmath]\psi(\phi^{-1}(x))[/ilmath]
In maths we would write this as:
- [ilmath]t=\psi\circ\phi^{-1}:\text{Im}_\phi(U\cap V)\rightarrow\text{Im}_\psi(U\cap V)[/ilmath]
Canonical coordinates
We will assign each point on the manifold a "canonical coordinate" - these are coordinates of the form [ilmath](i,x)[/ilmath] where a point [ilmath]p[/ilmath] on the manifold has coordinate [ilmath]x=\phi_i(p)[/ilmath] - so the [ilmath]i[/ilmath] is the chart identifier and the [ilmath]x[/ilmath] is the vector of the point in the chart.
As you know charts can overlap, what we'll do is centre the charts and define a canonical coordinate as having a "cut off" point. once we go passed this point we consider it in a different chart. I will do this in the circle now.
The circle
You "need" 4 charts to cover a circle. You can do it in less, but 4 is a very natural number. Notice also it is finite. This means we can do it on a computer!
4 natural charts for the circle, [ilmath]\varphi_1,\ \varphi_2,\ \varphi_3[/ilmath] and [ilmath]\varphi_4[/ilmath] |
As you can see these are really easy coordinate charts, they're projections straight down onto a line. This makes them great to work out. Provided that your planet is a "heightmap" (that is you have a sphere where you move vertices in/out radially and don't have things like caves which would change the topology of your planet - beyond repair of this model if your tunnel had an exit) this will work well.
Pitfalls
The problem with these straight-down projections is it doesn't preserve distance. Chunks nearer the bounds of the line cover larger portions of the circle than the same sized chunk near the middle, as this picture shows:
Notice that [ilmath]\ell_1[/ilmath] and [ilmath]\ell_2[/ilmath] are the same in the drawing, but [ilmath]\theta_1[/ilmath] is significantly larger than [ilmath]\theta_2[/ilmath]! |
Angular charts
While this isn't a problem mathematically, it would be much easier if you could use a for-loop and "iterate" over the area, hence the need for angles instead.
Angular chart on [ilmath]A[/ilmath] |
We now have the charts:
- [ilmath]\psi_1:A\rightarrow\mathbb{R} [/ilmath] given by [ilmath]\psi_1:(x,y)\rightarrow \arctan(\frac{x}{y})[/ilmath]
- [ilmath]\psi_2:B\rightarrow\mathbb{R} [/ilmath] given by [ilmath]\psi_2:(x,y)\rightarrow \arctan(\frac{y}{x})[/ilmath]
- [ilmath]\psi_3:A\rightarrow\mathbb{R} [/ilmath] given by [ilmath]\psi_3:(x,y)\rightarrow \arctan(\frac{x}{y})[/ilmath]
- [ilmath]\psi_4:B\rightarrow\mathbb{R} [/ilmath] given by [ilmath]\psi_4:(x,y)\rightarrow \arctan(\frac{y}{x})[/ilmath]
Side-by-side comparisons
Comparing charts |
Note the regular spacing when using angles.
My location on a circle
Given a point [ilmath]p[/ilmath] on a circle we will assign it a "natural" or "canonical" coordinate of the form [ilmath](i,x)[/ilmath] where [ilmath]i[/ilmath] is between 0 and 3 (this is the chart number) and [ilmath]x[/ilmath] is the coordinate in that chart.
Now you can say "there is a factory at [ilmath](1,0.3)[/ilmath] and know EXACTLY where that factory is. These coordinates don't smush together and stay "fairly" regular. You cannot cover a circle nor a sphere in 1 chart (however the bit you cannot cover has measure 0 - so when integrating in spherical/polar coordinates you can ignore it)
Equations
The 4 charts we use cover sections [ilmath]A,\ B,\ C[/ilmath] and [ilmath]D[/ilmath] of the circle. There's a lot of overlap. We must define "canonical" coordinates.
For a circle of radius 1 the angles at [ilmath]45^\circ[/ilmath] to the poles occur when the height is exactly [ilmath]\frac{\sqrt{2} }{2} [/ilmath], so if given a point [ilmath]p=(x,y)[/ilmath] on the circle we need to decide which "chart" it maps to.
- If [ilmath]y>\frac{\sqrt{2} }{2} [/ilmath] then we use the top chart ([ilmath]\psi_1[/ilmath], on [ilmath]A[/ilmath])
- Return [ilmath](1,\arctan(\frac{x}{y}))[/ilmath]
- If [ilmath]y<-\frac{\sqrt{2} }{2} [/ilmath] then we use the bottom chart ([ilmath]\psi_3[/ilmath] on [ilmath]C[/ilmath])
- Return [ilmath](3,\arctan(\frac{x}{y}))[/ilmath]
- If [ilmath]x>\frac{\sqrt{2} }{2} [/ilmath] then we use the right chart ([ilmath]\psi_2[/ilmath] on [ilmath]B[/ilmath])
- Return [ilmath](2,\arctan(\frac{y}{x}))[/ilmath]
- Otherwise
- Return [ilmath](4,\arctan(\frac{y}{x}))[/ilmath]
Going the other way
Elementary trigonometry will allow one to go from an angle to the correct chart.
TODO: Fill this in - OP should be able to figure it out
Given a coordinate [ilmath](i,\theta)[/ilmath]:
- If [ilmath]i=1[/ilmath] then
- Return [ilmath]r(\sin(\theta),\cos(\theta))[/ilmath]
So forth
Why not just use the angles (and radius)?
In a circle to use angles we must have stuff in a range, [ilmath][0,360)[/ilmath] this denotes the set [ilmath]\{x[/ilmath] the problem is that if you're at [ilmath]0[/ilmath] you suddenly jump to 360, you cannot go "backwards" smoothly (you suddenly jump), you also cannot go smoothly back around to zero when you're by [ilmath]360[/ilmath] - but this is an open end of the interval, which means for an [ilmath]x\in(0,360)[/ilmath] - any [ilmath]x[/ilmath] you like - there is a small amount you can go either way. Always. If you're at [ilmath]359.98[/ilmath] you can still go [ilmath]0.01[/ilmath] in either direction without jumping.
Another problem is that you'd use [ilmath]\text{Arctan} [/ilmath] to get the angles, this'll have 2 discontinuities, when [ilmath]y[/ilmath] = 0 (if you define vertically up as an angle of [ilmath]0[/ilmath])
Also it'll not be able to distinguish which "quarter" you're in, as [ilmath]\frac{x}{y}=\frac{-x}{-y}[/ilmath] thus the top right and bottom left have the same angle.
With spheres this problem becomes a little complex. Usually a point has 2 angles, an "up down" angle and a "around" angle. When you're at a pole any "around" angle will work. So you cannot move locally in the coordinates either, they're also far from unique. Add floating point numbers in there and this becomes a real problem.
Using nice charts (like we do) fixes all of this.
The sphere
We will use 6 charts.
TODO: picture is worth a thousand words
Like a cube-map, we shall assign cut-offs by giving each chart [ilmath]90^\circ[/ilmath] to "chart", notice that the charts (both the angle ones and the straight down projections) are able to cover a range of [ilmath]180^\circ[/ilmath] - this means we have plenty of overlap and makes it easy to move between them - in fact you can move an angle of [ilmath]< 45^\circ[/ilmath] without leaving the chart ALWAYS. If you use the angular ones the chunks will also all be the same size, so you can talk of regions of so many square kilometers about any point in our canonical coordinates without problem. This is a large chunk of the planet's surface.
The charts
TODO: Give them explicitly