reverse function

Hello,

I have code for conversion of longitude and latitude and I need help to reverse the function so it will work in opposite direction:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
float LongitudeDeg = argv[1]; // some longitude
float LatitudeDeg = argv[2]; // some latitude
int LongitudeData;
int LatitudeData;
uint32_t u,v,l,n;
l=15; // l range is 2-29

LongitudeData = (int)(0.5 + (180 + LongitudeDeg) * (0x2000000 / 15));
LatitudeData = (int)(0.5 + (90 - LatitudeDeg) * (0x8000000 / 45));

if ( LongitudeData > 0x30000000)
	LongitudeData -= 0x30000000;
if (LongitudeData < 0)
	LongitudeData += 0x30000000

if ( LatitudeData > 0x20000000 )
	LatitudeData -= 0x20000000;
if ( LatitudeData < 0 )
	LatitudeData += 0x20000000);

n = 30 - l;
u = LongitudeData >> n;
v = LatitudeData >> n;


On start of the code we know longitude,latitude and l. And the result is u and v. And I need function when I will know the u and v, possibly l too, to calculate longitude, latitude.

Can you help with it?
Last edited on
Do you round down intentionally on lines 6 and 7 by forcing division before multiplication?

Lines 20 and 21 do bitshift, but the *Data variables were set from signed values.

On the reverse:
1. Do reverse bitshift
2. Ignore cyclic clamping (lines 9-17)
3. Ignore rounding (lines 6-7)
4. Solve *Deg's from the equations
5. Verify accuracy with sufficient testing
Topic archived. No new replies allowed.