Maths: Whats the best coordinate system when talking about positions on a sphere ?

Started by
8 comments, last by kelumden 17 years, 9 months ago
G'day, For fun im gonna take a shot at getting spherical game worlds happerning. I'm going to use a spherical coordinate system and then just translate that back to the cartesian coordinate system for rendering and the like. I've done a bit of googling on coordinate systems and polar looked promising, but it looked liked it was only in 2D :(. I'm sure the geogography would of came up with some sort of coordinate system for mapping the earth, and yeah, I just need to know what that is, and if anyone knows of a few good resources on using that coordinate system I'ld be most appricative. TIA
Advertisement
I can't offer a definite answer to this (someone else probably can though), but I will throw out a couple of things.

The 3D equivalent to 2D polar coordinates are usually called 'spherical' coordinates (naturally), so that gives you something to google for. However, spherical coordinates are not particularly well suited for continuous smooth motion over a sphere.

In general the problem here is mapping a rectangular grid to a sphere, which is somewhat problematic. Perhaps someone with a stronger background in math can formalize this and perhaps suggest some ways to approach this problem, but meanwhile I'll tell you how I would do it.

If I were making a game that took place on the surface of a sphere, I probably wouldn't try to maintain separate coordinate systems for game simulation and rendering. Instead, I'd use standard methods (oft discussed here in reference to terrain) to align and position the objects relative to the sphere surface as they moved about. This is not too hard, and more or less addresses the issue of moving on the surface of the sphere in a consistent manner.

AI and such might be a little trickier, but not much, I don't think. The shortest path between two objects on the sphere can be calculated easily, and with a little vector math you can also determine, for example, what direction to turn to approach this path. Granted, there may be a few more details to manage than with a Cartesian grid, but it should be doable.

There may be a better solution than what I've proposed here, but the above is what immediately comes to mind.
The problem with using spherical co-ordinates is that they form vertex bunching near the poles with singularities at the poles themselves. This can cause all kinds of problems for things like texture mapping and game logic where you're trying to map cartesian grids onto the sphere surface.

There was an excelent post about this problem a couple weeks back so I just had a rummage through the threads and managed to dig up this link for you which gives a good solution:

http://mathproofs.blogspot.com/2005/07/mapping-cube-to-sphere.html

Hope that helps.
[size="1"] [size="4"]:: SHMUP-DEV ::
You may be looking for Map projections. Which one to use is up to you; there's plenty to choose from.

As far as coordinates are concerned, the typical one is latitude and longitude. Expository article here. But that exhibits the same bunching as the regular spherical coordinates.
---New infokeeps brain running;must gas up!
I am not sure what exactly you are trying to do with your coordinates, but in some cases the best option is just using the usual 3 coordinates. For instance, if you want to generate a procedural texture on the sphere and you want to avoid the bunching effect, you can use a 3D texture, where you map any point in the space to a color (or whatever the texture encodes) and you only use the values on the surface of your sphere.

"you can use a 3D texture"

o.O I thought all textures are 2D images ???
Quote:Original post by f001error
o.O I thought all textures are 2D images ???


clicky
Lat/long is the same as spherical polar coordinates (just expressed in degrees not radians, typically), and yeah, that's the usual system for points on a sphere. As others have said, if you want to randomly select a point with even probability you need to do some fancy footwork to avoid bunching around the poles. The previous thread on this topic (use the search) had links to some good algorithms for that.

If you want a 3D tile based system on a spherical world, the cube-to-sphere mapping linked to earlier looks interesting. Alternatively you can use an icosahedral base mesh (20 triangular faces) and subdivide each face as finely as you need to get a triangularly tiled world (with 20×n² tiles).
Wikipedia knows all.

Volume rendering
---New infokeeps brain running;must gas up!
Quote:Original post by Bob Janova
Lat/long is the same as spherical polar coordinates (just expressed in degrees not radians, typically), and yeah, that's the usual system for points on a sphere. As others have said, if you want to randomly select a point with even probability you need to do some fancy footwork to avoid bunching around the poles. The previous thread on this topic (use the search) had links to some good algorithms for that.

If you want a 3D tile based system on a spherical world, the cube-to-sphere mapping linked to earlier looks interesting. Alternatively you can use an icosahedral base mesh (20 triangular faces) and subdivide each face as finely as you need to get a triangularly tiled world (with 20×n² tiles).


An icosahedral mesh has been used by Traveller (tm) (80's Sci-Fi RPG) to depict planets.

The mesh is quite regular with one exception ! At each summit of the base icosahedron, there will ALWAYS be five (5) adjacent triangles instead of six at any other place on the shape. This leads to some problem when moving around the sphere.

Splitting the triangles forming the base icosahedron also introduce some distorsion if the summits of the new triangle are projected on the sphere but this is something that can be accounted for.

This technique is quite helpfull but also needs memory ! The basic shape is an icosahedron with 20 faces. Using a fractal-like approach, each triangle will be from now on divided into four (4) triangles by cutting each edge in two equal parts. This process is repeated as much as needed !

What can also be interesting is the length of one side of each triangle (approximated, because there will be a distorsion due to projecting the triangle on the sphere) but the more iteration applied the less important the distorsion!

Because the icosahedron is made of equilateral triangles, the length of the edge of a triangle is equal to the radius of the circumscribed sphere. If we consider Earth, its radius is (approxiamtively) 6378.135 km (from WikiPedia).

Base shape : 20 triangles - Edge length: 1.0000 ( 6378.1350 km )
Iteration 1 : 80 triangles - Edge length: 0.5000 ( 3189.0675 km )
Iteration 2 : 320 triangles - Edge length: 0.2500 ( 1594.5338 km )
Iteration 3 : 1280 triangles - Edge length: 0.1250 ( 797.2669 km )
Iteration 4 : 5120 triangles - Edge length: 0.0625 ( 398.6334 km )
Iteration 5 : 20480 triangles - Edge length: 0.03125 ( 199.3167 km )
Iteration 6 : 81920 triangles - Edge length: 0.015625 ( 99.6584 km )
Iteration 7 : 327680 triangles - Edge length: 0.0078125 ( 49.8292 km )
Iteration 8 : 1310720 triangles - Edge length: 0.00390625 ( 24.9146 km )
Iteration 9 : 5242880 triangles - Edge length: 0.001953125 ( 12.4573 km )

In the above table, the first value is the number of triangles defining the surface, the second, the relative length of an edge and the third, the length of the edge relative to Earth.

For comparaison, one degree is equal to 111.3195 km and one minute, to 1.8553 km.

I hope this will help you.

This topic is closed to new replies.

Advertisement