ID:146904
 
For my world program I'm wanting to display the users coordinants in longitude and laditude along with loading the locations of various places and things by longitude and laditude coordinants.

After searching for awhile I found an equation for the conversion here http://mathworld.wolfram.com/ MillerCylindricalProjection.html . The longitude coordinants were simple enough and I got them working however laditude wasn't nearly as simple.

Here's what I have
#define _E  2.718281828459045
#define PI 3.14

proc
arctan(x)
var/y=arcsin(x/sqrt(1+x*x))
if(x>=0) return y
return -y
GetLon(x)
x = x * 360 / world.maxx - 180
return x
GetLat(y)
y = y * 180 / world.maxx - 90
y = (5/4)*arctan(_E ** (4/5*y)) - (5/8)*PI
return y


Unfortunantly it doesn't generate good values for the laditude. The two problems I can see I might have is that the arctan function(made by LummoxJR in an older post) isn't handlings the values in the given range properly. Or I haven't converted the y coordinate to the proper scale. The current scale I used was just a guess as the site I got the algorithm off of didn't specify the appropriate ranges for the x and y values to generate proper results.
The only problem I can see off hand is that you are multiplying the arctan by 5/4, when the formula uses 5/2. It would just be off by a factor of 2 though and I think you'd have spotted that easily enough.

http://mathworld.wolfram.com/ CylindricalEquidistantProjection.html may be a bit easier to convert. If you start at 0 degrees, it means <font face=symbol>l</font> is x and <font face=symbol>f</font> is y with no icky math beyond converting the maxx/maxy scale to degrees.

It might help if you explain the context for this proc. Projections distort the map, so trying to make meaningful conversions is difficult. If you want to put this in a game, all turfs at y = maxy are the same point on the north pole. Occupy any of those turfs and physically you should occupy all of them. You should be able to step from any of those turfs to any turf on the next line down because they are all a tiny distance away from the north pole on the sphere represented by the map.
In response to Shadowdarke
http://mathworld.wolfram.com/ CylindricalEquidistantProjection.html may be a bit easier to convert. If you start at 0 degrees, it means <font face=symbol>l</font> is x and <font face=symbol>f</font> is y with no icky math beyond converting the maxx/maxy scale to degrees.

Yeah it certainly looks cleaner. I'll have to try and see how close it gets as I'm not sure exactly which projection was used to generate the map.

It might help if you explain the context for this proc. Projections distort the map, so trying to make meaningful conversions is difficult.

The main idea was that I could get coordinants of real world locations and easily be able to place them on the map without having to eyeball it.

If you want to put this in a game, all turfs at y = maxy are the same point on the north pole. Occupy any of those turfs and physically you should occupy all of them. You should be able to step from any of those turfs to any turf on the next line down because they are all a tiny distance away from the north pole on the sphere represented by the map.

Yeah I'm planning on just glossing over that fact as far as movement is concerned :). Though the game I had in mind is based mainly on ocean travel making the poles innaccessable.
In response to Theodis
Theodis wrote:
Yeah it certainly looks cleaner. I'll have to try and see how close it gets as I'm not sure exactly which projection was used to generate the map.

According to this, it uses "geographic projection". A Google search says that this means the latitude and longitude lines are spaced equally; which makes calculating them a lot easier!