Difference between revisions of "Notes:Spherical coordinates"

From Maths
Jump to: navigation, search
(Created page with "{{Note|This is in reference to [http://gamedev.stackexchange.com/questions/108667/how-to-load-a-spherical-planet-and-its-regions this question] and not a part of the site, I n...")
 
m (The circle)
 
(One intermediate revision by the same user not shown)
Line 17: Line 17:
  
 
==Going between charts==
 
==Going between charts==
 +
[[File:Transition map.JPG|thumb|Transition map {{M|\psi\circ\varphi^{-1} }} on a topological {{n|manifold}} {{M|M}}]]
 
''(see [[transition map]] - it has a good picture)''<br/>
 
''(see [[transition map]] - it has a good picture)''<br/>
 
Take two charts, {{M|\phi:U\rightarrow\mathbb{R}^n}} and {{M|\psi:V\rightarrow\mathbb{R}^n}} where we have:
 
Take two charts, {{M|\phi:U\rightarrow\mathbb{R}^n}} and {{M|\psi:V\rightarrow\mathbb{R}^n}} where we have:
Line 40: Line 41:
 
In maths we would write this as:
 
In maths we would write this as:
 
*{{M|1=t=\psi\circ\phi^{-1}:\text{Im}_\phi(U\cap V)\rightarrow\text{Im}_\psi(U\cap V)}}
 
*{{M|1=t=\psi\circ\phi^{-1}:\text{Im}_\phi(U\cap V)\rightarrow\text{Im}_\psi(U\cap V)}}
[[File:Transition map.JPG|thumb|Transition map {{M|\psi\circ\varphi}} on a topological {{n|manifold}} {{M|M}}]]
+
 
  
 
==Canonical coordinates==
 
==Canonical coordinates==
Line 48: Line 49:
  
 
==The circle==
 
==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. You can give every point a "coordinate" as a chart number then the coordinates in that chart. The problem is this isn't unique (as we know, charts can overlap) - we need to fix this.  
+
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!
 
+
<center>
{{Todo|Picture of circle with 4 natural charts}}
+
{| class="wikitable" border="1"
 +
|-
 +
![[Image:Charting A Circle.JPG|650px]]
 +
|-
 +
| 4 natural charts for the circle, {{M|\varphi_1,\ \varphi_2,\ \varphi_3}} and {{M|\varphi_4}}
 +
|}
 +
</center>
  
 
As you can see these are really easy coordinate charts, they're [[Projector|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.  
 
As you can see these are really easy coordinate charts, they're [[Projector|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:
 +
<center>
 +
{| class="wikitable" border="1"
 +
|-
 +
![[Image:Pitfalls of circle chart.JPG|650px]]
 +
|-
 +
| Notice that {{M|\ell_1}} and {{M|\ell_2}} are the same in the drawing, but {{M|\theta_1}} is significantly larger than {{M|\theta_2}}!
 +
|}
 +
</center>
  
 +
===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.
 +
<center>
 +
{| class="wikitable" border="1"
 +
|-
 +
![[Image:Angular chart on a circle.JPG|650px]]
 +
|-
 +
| Angular chart on {{M|A}}
 +
|}
 +
</center>
 +
We now have the charts:
 +
* {{M|\psi_1:A\rightarrow\mathbb{R} }} given by {{M|\psi_1:(x,y)\rightarrow \arctan(\frac{x}{y})}}
 +
* {{M|\psi_2:B\rightarrow\mathbb{R} }} given by {{M|\psi_2:(x,y)\rightarrow \arctan(\frac{y}{x})}}
 +
* {{M|\psi_3:A\rightarrow\mathbb{R} }} given by {{M|\psi_3:(x,y)\rightarrow \arctan(\frac{x}{y})}}
 +
* {{M|\psi_4:B\rightarrow\mathbb{R} }} given by {{M|\psi_4:(x,y)\rightarrow \arctan(\frac{y}{x})}}
 +
 +
 +
===Side-by-side comparisons===
 +
<center>
 +
{| class="wikitable" border="1"
 +
|-
 +
![[Image:Comparing charts on a circle.JPG|650px]]
 +
|-
 +
| Comparing charts
 +
|}
 +
</center>
 +
Note the regular spacing when using angles.
 
===My location on a circle===
 
===My location on a circle===
 
Given a point {{M|p}} on a circle we will assign it a "natural" or "canonical" coordinate of the form {{M|(i,x)}} where {{M|i}} is between 0 and 3 (this is the chart number) and {{M|x}} is the coordinate in that chart.  
 
Given a point {{M|p}} on a circle we will assign it a "natural" or "canonical" coordinate of the form {{M|(i,x)}} where {{M|i}} is between 0 and 3 (this is the chart number) and {{M|x}} is the coordinate in that chart.  
Line 60: Line 104:
  
 
====Equations====
 
====Equations====
Given a point {{M|(x,y)}} on a circle about the origin, where {{M|y>0}} and {{M|x}} is between {{M|-\frac{\sqrt{2} }{2} }} and {{M|\frac{\sqrt{2} }{2} }} (thus in the domain of the zeroth chart) the coordinate of this is {{M|(0,x)}} - this "projects" the coordinate straight down, because the circle is curved this isn't quite uniform.
+
The 4 charts we use cover sections {{M|A,\ B,\ C}} and {{M|D}} of the circle. There's a lot of overlap. We must define "canonical" coordinates.
{{Todo|Picture of non-uniform downwards projection}}
+
 
+
It would be more uniform to have a different charting scheme where we use angles.  
+
  
{{Todo|Charting with angles picture}}
+
For a circle of radius 1 the angles at {{M|45^\circ}} to the poles occur when the height is exactly {{M|\frac{\sqrt{2} }{2} }}, so if given a point {{M|1=p=(x,y)}} on the circle we need to decide which "chart" it maps to.
 +
# If {{M|y>\frac{\sqrt{2} }{2} }} then we use the top chart ({{M|\psi_1}}, on {{M|A}})
 +
#* Return {{M|(1,\arctan(\frac{x}{y}))}}
 +
# If {{M|y<-\frac{\sqrt{2} }{2} }} then we use the bottom chart ({{M|\psi_3}} on {{M|C}})
 +
#* Return {{M|(3,\arctan(\frac{x}{y}))}}
 +
# If {{M|x>\frac{\sqrt{2} }{2} }} then we use the right chart ({{M|\psi_2}} on {{M|B}})
 +
#* Return {{M|(2,\arctan(\frac{y}{x}))}}
 +
# Otherwise
 +
#* Return {{M|(4,\arctan(\frac{y}{x}))}}
  
We have now charted the circle.
+
====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}}
  
====Why not just use the angles (and radius)?====
+
Given a coordinate {{M|(i,\theta)}}:
 +
# If {{M|1=i=1}} then
 +
#* Return {{M|r(\sin(\theta),\cos(\theta))}}
 +
So forth
 +
==Why not just use the angles (and radius)?==
 
In a circle to use angles we must have stuff in a range, {{M|[0,360)}} this denotes the set {{M|\{x|0\le x< 360\} }} the problem is that if you're at {{M|0}} 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 {{M|360}} - but this is an open end of the interval, which means for an {{M|x\in(0,360)}} - any {{M|x}} you like - there is a small amount you can go either way. Always. If you're at {{M|359.98}} you can still go {{M|0.01}} in either direction without jumping.
 
In a circle to use angles we must have stuff in a range, {{M|[0,360)}} this denotes the set {{M|\{x|0\le x< 360\} }} the problem is that if you're at {{M|0}} 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 {{M|360}} - but this is an open end of the interval, which means for an {{M|x\in(0,360)}} - any {{M|x}} you like - there is a small amount you can go either way. Always. If you're at {{M|359.98}} you can still go {{M|0.01}} in either direction without jumping.
  

Latest revision as of 18:48, 23 September 2015

This is in reference to this question and not a part of the site, I needed math-markup

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

Transition map [ilmath]\psi\circ\varphi^{-1} [/ilmath] on a topological [ilmath]n[/ilmath]-manifold [ilmath]M[/ilmath]

(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:

  1. 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
  2. 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!

Charting A Circle.JPG
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:

Pitfalls of circle chart.JPG
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 a circle.JPG
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 on a circle.JPG
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.

  1. 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]
  2. 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]
  3. 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]
  4. 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]:

  1. 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