1. ## Reversing forumla

Hey there, I am an Iphone developer from New Zealand and I am currently working on a project that requires me to use some equations for calculating X and Y coordinates from latitude and longitude values.

I have a function that converts lat and long to x and y and it is working perfectly in my application. However now i need to do the reverse of this. I need to convert X and Y values into lat and long.

I have gotten halfway by myself, i have worked out the longitude side of things, but the other line is more complicated.

This is what I started with:

x = (offset + radius * longitude * M_PI / 180.0);
y = (offset - radius * logf((1.0 + sinf(latitude * M_PI / 180.0)) / (1.0 - sinf(latitude * M_PI / 180.0))) / 2.0);

and this is where i have gotten so far:

float longitude = (x - offset) * 180 / radius / M_PI;

Could someone please give me a hand with the second line.

If you could please lay this out in steps for me it would be very much appreciated.
I need some insight as to how to do this myself.
Cheers

2. ## Re: Reversing forumla

Originally Posted by howsyourface
Hey there, I am an Iphone developer from New Zealand and I am currently working on a project that requires me to use some equations for calculating X and Y coordinates from latitude and longitude values.

I have a function that converts lat and long to x and y and it is working perfectly in my application. However now i need to do the reverse of this. I need to convert X and Y values into lat and long.

I have gotten halfway by myself, i have worked out the longitude side of things, but the other line is more complicated.

This is what I started with:

x = (offset + radius * longitude * M_PI / 180.0);
y = (offset - radius * logf((1.0 + sinf(latitude * M_PI / 180.0)) / (1.0 - sinf(latitude * M_PI / 180.0))) / 2.0);

and this is where i have gotten so far:

float longitude = (x - offset) * 180 / radius / M_PI;

Could someone please give me a hand with the second line.

If you could please lay this out in steps for me it would be very much appreciated.
I need some insight as to how to do this myself.
Cheers
Dear howsyourface,

Your formula for y is not clear, do you mean,

$\displaystyle y=\mbox{offset}-\frac{\mbox{radius}\times \log f\left[(1.0 + \sin f\left(latitude\times \frac{M_{PI}}{180.0}\right)\right]}{2.0\left[1.0 - \sin f\left(latitude\times\frac{M_{PI}}{180.0}\right) \right]}$

Try to learn some simple LaTeX, then you would be able to clearly present your equations. http://www.mathhelpforum.com/math-he...orial-266.html

3. ## Re: Reversing forumla

Originally Posted by howsyourface
y = (offset - radius * logf((1.0 + sinf(latitude * M_PI / 180.0)) / (1.0 - sinf(latitude * M_PI / 180.0))) / 2.0);