Question Calculating surface tiles bounds

SolarLiner

It's necessary, TARS.
Addon Developer
Joined
Jun 14, 2010
Messages
1,847
Reaction score
2
Points
0
Location
404 ROAD NOT FOUND
Hi,
So, I've recently found my way back into coding for my little TileMaker project which you may remember I started sometime ago. (Well actually due to HDD failure it's like it never was, but anyway) EDIT: Actually I had put it up in Codeplex, so I now have the old code again, which is cool

So I have my Tile class which represents, well, a single tile (it doesn't hold an image, just the tile coordinates, level and parent body), I'd like to calculate the bounds in long/lat coordinates.
I could be using that to figure out in which tile a point is given its coordinates and the desired level.

If anyone could help me with the maths, it would be great! :cheers:
 
Last edited:

jarmonik

Well-known member
Orbiter Contributor
Addon Developer
Beta Tester
Joined
Mar 28, 2008
Messages
2,666
Reaction score
795
Points
128
You can use D3D9Client to study the layout of a planet or a moon. Set the "TileDebug" variable from the config file to 1. After that you will see tile numbers and boundries.

Lvl 4 countains only 2 tiles, western and eastern hemispheres. After that every level will split the tiles in four sub section. So, western and eastern hemispheres are both splitted in four sub sections resulting 8 tiles in level 5. Then each go the 8 tiles will be split in four resulting 32 tiles on level 6.

So, if you have a geo-centric vector and you want the know which tile is pointed by the vector.

1) Convert the vector in the planet's local coordinates and compute the lng, lat.
2) Choose the hemisphere (i.e. section)
3) Split the section in four sub-sections
4) Choose the sub-section pointed by lng, lat and goto step 3 until you have reached the level you want.

So, it would be like a function splitting the input section in four sub-sections and then calling it-self to get to the next level. So, I guess, only math it requires is to split PI in half and making some bounds checks. At least, that's how I have understood it.
 

SolarLiner

It's necessary, TARS.
Addon Developer
Joined
Jun 14, 2010
Messages
1,847
Reaction score
2
Points
0
Location
404 ROAD NOT FOUND
I don't have a geo-centric vector, but the latitude and longitude of the point already. (which is going to save me some more maths)

"Level 4 has 2 tiles", I'd take you're talking about the Beta tile system, which I hoped to integrate at some point, but right now I'm focused in making the tool for the Orbiter 2010 surface tiles way. I am still saving this as it is a good 'in the dark' approach, although I fear it won't be the most optimized.

---------- Post added at 23:21 ---------- Previous post was at 23:03 ----------

Although that makes me think, if the number of tiles per level is fixed (as in independent of the planet's surface area), then it would be really easy to make a function that returns the tile coordinates from lat/lon input.

So, making a little research, I found this: http://www.orbiterwiki.org/wiki/surface_tile
It says "The Earth is split into 2048 tiles in latitude and 4096 in longitude."
Would that be for level 1? If it is, and knowing that you need 4 tiles in one level to cover the same area as one in the directly lower level, then the number of tiles per axis double with each level.
Which gives:
Level 1: 2048x4096
Level 2: 4096x8192
Level 3: 16384x8192
Etc.

And it comes with a handy formula as well! So modifying it a bit:
[math]Latitude\, Coordinate = \left \lfloor latitude\times \frac{2^{(10+level)}}{90} \right \rfloor[/math]
[math]Longitude\, Coordinate = \left \lfloor lontigude\times \frac{2^{(11+level)}}{180} \right \rfloor[/math]
Sounds easy enough!

Oh, and I have made a quick test, it seems that the anchor point is the bottom left point of the texture, which means that tile N000 E000 will have it's bottom-left corner at 0° N, 0° E exactly. Which means I can now compute the 4 corners by calculating the lat/long coordinates of the surrounding tiles.
 
Last edited:
Top