simplified distance formula. more precise values for ditance testing

This commit is contained in:
Emil Tin 2012-08-23 19:14:12 +02:00
parent b055334e73
commit c08f49c65e
2 changed files with 8 additions and 13 deletions

View File

@ -367,17 +367,10 @@ inline double ApproximateDistance( const int lat1, const int lon1, const int lat
assert(lat2 != INT_MIN); assert(lat2 != INT_MIN);
assert(lon2 != INT_MIN); assert(lon2 != INT_MIN);
static const double DEG_TO_RAD = 0.017453292519943295769236907684886; static const double DEG_TO_RAD = 0.017453292519943295769236907684886;
//Earth's quatratic mean radius for WGS-84 static const double EARTH_RADIUS_IN_METERS = 6372797.560856; //Earth's quatratic mean radius for WGS-84
static const double EARTH_RADIUS_IN_METERS = 6372797.560856; double latArc = lat2-lat1;
double latitudeArc = ( lat1/100000. - lat2/100000. ) * DEG_TO_RAD; double lonArc = lon2-lon1;
double longitudeArc = ( lon1/100000. - lon2/100000. ) * DEG_TO_RAD; return EARTH_RADIUS_IN_METERS * DEG_TO_RAD * sqrt( latArc*latArc + lonArc*lonArc ) / 100000.0;
double latitudeH = sin( latitudeArc * 0.5 );
latitudeH *= latitudeH;
double lontitudeH = sin( longitudeArc * 0.5 );
lontitudeH *= lontitudeH;
double tmp = cos( lat1/100000. * DEG_TO_RAD ) * cos( lat2/100000. * DEG_TO_RAD );
double distanceArc = 2.0 * asin( sqrt( latitudeH + tmp * lontitudeH ) );
return EARTH_RADIUS_IN_METERS * distanceArc;
} }
inline double ApproximateDistance(const _Coordinate &c1, const _Coordinate &c2) { inline double ApproximateDistance(const _Coordinate &c1, const _Coordinate &c2) {

View File

@ -16,8 +16,10 @@ DEFAULT_GRID_SIZE = 100 #meters
ORIGIN = [1,1] ORIGIN = [1,1]
def set_grid_size meters def set_grid_size meters
@zoom = 0.001*(meters.to_f/111.21) #the constant is calculated (with BigDecimal as: 1.0/(DEG_TO_RAD*EARTH_RADIUS_IN_METERS
#see ApproximateDistance() in ExtractorStructs.h
@zoom = meters.to_f*0.8990679362704610899694577444566908445396483347536032203503E-5
end end
def build_ways_from_table table def build_ways_from_table table