I am trying to write up a code using the known GPS position to caluate the distance to a given point>


long  distance  =  dist2Point(long latitudeOfPoint,long longitudeOfPoint)


and also distance to a given line which goes between to GPS points>


long  distance2Line  =  dist2Point(long latitudeOfPointStart,long longitudeOfPointStart, long latitudeOfPointEnd,long longitudeOfPointEnd)



any ideas how to do this by using snippets of existing code?


Thanks for all ideas

Views: 347

Reply to This

Replies to This Discussion

long get_distance(struct Location *loc1, struct Location *loc2)
 if(loc1->lat == 0 || loc1->lng == 0)
  return -1;
 if(loc2->lat == 0 || loc2->lng == 0)
  return -1;
 float dlat   = (float)(loc2->lat - loc1->lat);
 float dlong  = ((float)(loc2->lng - loc1->lng)) * scaleLongDown;
 return sqrt(sq(dlat) + sq(dlong)) * .01113195;


taken from navigation.pde

So its just to multiple it with * .01113195; to get meter? Great. so that is it?



No! You have to scale the longitude as you move north/south from the equator. See the factor scaleLongDown. It is calculated as:

// this is used to offset the shrinking longitude as we go towards the poles
float rads = (abs(next_WP.lat)/t7) * 0.0174532925;
scaleLongDown = cos(rads);
scaleLongUp = 1.0f/cos(rads);
I find this site full of useful info.

Reply to Discussion



Season Two of the Trust Time Trial (T3) Contest 
A list of all T3 contests is here. The current round, the Vertical Horizontal one, is here

© 2018   Created by Chris Anderson.   Powered by

Badges  |  Report an Issue  |  Terms of Service