0

I check the geo source code of Redis, and one statement I cannot understanding is double difference_longitude = asin(sin(distance) / cos(latr)); What's the asin(sin(distance) / cos(latr)) meaning? Is there any theory from the wikipedia?

http://download.redis.io/redis-stable/deps/geohash-int/geohash_helper.c

#define D_R (M_PI / 180.0)

static inline double deg_rad(double ang) { return ang * D_R; }
static inline double rad_deg(double ang) { return ang / D_R; }

int geohashBoundingBox(double longitude, double latitude, double radius_meters,
                       double *bounds) {
    if (!bounds) return 0;

    double lonr, latr;

    lonr = deg_rad(longitude);
    latr = deg_rad(latitude);

    if (radius_meters > EARTH_RADIUS_IN_METERS)
        radius_meters = EARTH_RADIUS_IN_METERS;
    double distance = radius_meters / EARTH_RADIUS_IN_METERS;
    double min_latitude = latr - distance;
    double max_latitude = latr + distance;

    /* Note: we're being lazy and not accounting for coordinates near poles */
    double min_longitude, max_longitude;
    **double difference_longitude = asin(sin(distance) / cos(latr));**
    min_longitude = lonr - difference_longitude;
    max_longitude = lonr + difference_longitude;

    bounds[0] = rad_deg(min_longitude);
    bounds[1] = rad_deg(min_latitude);
    bounds[2] = rad_deg(max_longitude);
    bounds[3] = rad_deg(max_latitude);
    return 1;
}
Mad Physicist
  • 107,652
  • 25
  • 181
  • 264
Jason
  • 1,115
  • 14
  • 25
  • 3
    It tells you that a meter on the equator corresponds to a smaller longitude difference than a meter close to the north pole. – Lutz Lehmann Sep 12 '16 at 12:53
  • @LutzL, Yes you are right, however why we use "asin(sin(distance) / cos(latr));"? why not used other formula, you know there are should be any formula can that meaning, is there any theory behind it or any wiki article can describe this formula? – Jason Sep 13 '16 at 01:42
  • `distance` refers to a path on the sphere, thus an angle relative to the center of the sphere. The sine is then the length of the secant, i.e., straight line segment. `cos(latr)` is the radius of the latitude circle, the quotient thus the sine of the angle on the latitude circle. – Lutz Lehmann Sep 13 '16 at 05:54
  • @ LutzL, thank you for your help. – Jason Sep 13 '16 at 05:55
  • @ LutzL,BTW , can you kindly help to check my another related Queu http://stackoverflow.com/questions/39461221/whats-the-difference-between-area-and-boundingbox-from-rediss-source-code ? – Jason Sep 13 '16 at 05:56

0 Answers0