🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Derive an equation with logarithmec and trigo functions in it

Started by
3 comments, last by D.C.Elington 4 years, 3 months ago

Hi all,

I am trying to derive an equation to compute the lat and lon variables given an x and y coordinates.
I already have the equations we are using in our game to derived the X and Y coordinates from lat and lon.
Now we want to derive the formula in reverse. the code bellow shows the original formula to retrieve the X and Y given Lat and Lon that we are using. Well, computing for Lon is easy as it just involves transpose and division but cant seem to figure out how to do it for the latitude since it involves log and tangent functions.
Care to help math gurus? ?

	float PI = 3.1416;
	float PI_4 = PI / 4;

	int x = (lon * PI / 180) * 6371;
	int y = log(tan(PI_4 + (lat * PI / 360))) * 6371;

	lon = x / ((PI / 180) * 6371);
	lat = ???

Advertisement

Why are you calling these variables x y lat and lon when your equation has not much to do with

https://en.wikipedia.org/wiki/Spherical_coordinate_system

?

You could do your log in a second transform. Reverse would be exp

arnero said:

Why are you calling these variables x y lat and lon when your equation has not much to do with

https://en.wikipedia.org/wiki/Spherical_coordinate_system

?

well the equation is used for our own implementation of mapping and rendering system and converts GPS coordinate of lat and lon to 3d coordinate, hence the name of the variables, and the equation works.
now we want to do the reverse thats why I asked as I dont have idea how to do it in reverse. It is for converting world coordinates X, Y (technically there is a Z) to lat and lon for our custom processing.

You could do your log in a second transform. Reverse would be exp

Thats why I asked, I dont know how to do it ?

lat = (360/pi) * [atan(exp(y/6371.0)) - pi/4] ?

You will probably want to clamp “exp(y/6371.0)” to < pi/2 to avoid receiving NaN from the atan (= inverse function of tan).
6371.0 is to force a floating point division in y/6371.0 since y is an integer.

This topic is closed to new replies.

Advertisement