I am trying to find a working algorithm to convert LAT/LONG to UTM, much the same as in a Garmin GPS. This so my autopilot can calculate it’s waypoints internally and not use the GPS itself. ·
Can anybody help? ·
Thanks, Yossi
The formulas are really long. I even bought a few um-FPUs to try to put it all in there. I won't say I gave up, but I have put that project on the back burner. I think it will take a lot of work. I'd like to see what you come up with. It was beyond me.
Instead of going all the way to UTM. There are formulas that take two lat/long points and give the distance and direction from one to the other. I was able to find some AWK code.
# input is lat1 long1 lat2 long2
# lat1 is [noparse][[/noparse]NS] deg min sec if using deg and min sec must = 0
# likewise if only deg then min and sec = 0
# long1 is [noparse][[/noparse]EW] deg min sec
# the 2's are like the 1's
# 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
# Example: N 53 09 02 W 01 50.75 0 N 52 12 19 W 0.25 0 0
# if the [noparse][[/noparse]NS] or [noparse][[/noparse]EW] don't match returns an error
BEGIN { r = 6371
kmToFeet = 3280.839895
degToRadians = 3.14159/180.0 }
{if ($1 != $9) {print "Error in lat ", $0 ; next}}
{if ($5 != $13) { print "Error in long ", $0; next}}
{lat1 = $2 + $3/60.0 + $4/3600.0
lat2 = $10 + $11/60.0 + $12/3600.0
long1 = $6 + $7/60.0 + $8/3600.0
long2 = $14 + $15/60.0 + $16/3600.0
deltaLat = lat2 - lat1
deltaLong = long2 - long1
deltaLat = deltaLat * degToRadians
deltaLong = deltaLong * degToRadians
lat1 = lat1 * degToRadians
lat2 = lat2 * degToRadians
a = sin(deltaLat/2)^2 + cos(lat1) * cos(lat2) * sin(deltaLong/2)^2
print a
dx = 2.0 * r * atan2(sqrt(a), sqrt(1-a))
bearing = atan2((-sin(deltaLong)*cos(lat2)), (cos(lat1) * sin(lat2) - sin(lat1) * cos(lat2) * cos(deltaLong)))
print $0
print "distance = ", dx, "bearing = ", bearing/degToRadians }
It's been a while since I looked at my code but what I did was take the difference between the target lat/long and current lat/long to give me an X/Y position and then perform a couple of trig calculations to give me distance and bearing.
Comments
http://www.ibm.com/developerworks/java/library/j-coordconvert/
The formulas are really long. I even bought a few um-FPUs to try to put it all in there. I won't say I gave up, but I have put that project on the back burner. I think it will take a lot of work. I'd like to see what you come up with. It was beyond me.
Here's another link:
www.uwgb.edu/dutchs/UsefulData/UTMFormulas.HTM
HTH, Chris
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
I'm not scared of your robot. I'm covered by Old Glory (youtube)
# input is lat1 long1 lat2 long2
# lat1 is [noparse][[/noparse]NS] deg min sec if using deg and min sec must = 0
# likewise if only deg then min and sec = 0
# long1 is [noparse][[/noparse]EW] deg min sec
# the 2's are like the 1's
# 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
# Example: N 53 09 02 W 01 50.75 0 N 52 12 19 W 0.25 0 0
# if the [noparse][[/noparse]NS] or [noparse][[/noparse]EW] don't match returns an error
BEGIN { r = 6371
kmToFeet = 3280.839895
degToRadians = 3.14159/180.0 }
{if ($1 != $9) {print "Error in lat ", $0 ; next}}
{if ($5 != $13) { print "Error in long ", $0; next}}
{lat1 = $2 + $3/60.0 + $4/3600.0
lat2 = $10 + $11/60.0 + $12/3600.0
long1 = $6 + $7/60.0 + $8/3600.0
long2 = $14 + $15/60.0 + $16/3600.0
deltaLat = lat2 - lat1
deltaLong = long2 - long1
deltaLat = deltaLat * degToRadians
deltaLong = deltaLong * degToRadians
lat1 = lat1 * degToRadians
lat2 = lat2 * degToRadians
a = sin(deltaLat/2)^2 + cos(lat1) * cos(lat2) * sin(deltaLong/2)^2
print a
dx = 2.0 * r * atan2(sqrt(a), sqrt(1-a))
bearing = atan2((-sin(deltaLong)*cos(lat2)), (cos(lat1) * sin(lat2) - sin(lat1) * cos(lat2) * cos(deltaLong)))
print $0
print "distance = ", dx, "bearing = ", bearing/degToRadians }
Any chance to did up your formulas? Don't need the whole code just the trig. If you can find it. No big deal if not.
Thanks, Chris KE6GS
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
I'm not scared of your robot. I'm covered by Old Glory (youtube)
Here is my solution;
The difference in lat/long from where you are to where you want to be are stored in values distN and DistE
I'll attach the whole program so you can check it out further.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
I'm not scared of your robot. I'm covered by Old Glory (youtube)