Monday, September 7, 2015

Finding the center of Three points

Here's a fun math puzzle for you..  given 3 GPS locations find the center point.

pt circleCenter(pt A, pt B, pt C) {

    float yDelta_a = B.y - A.y;
    float xDelta_a = B.x - A.x;
    float yDelta_b = C.y - B.y;
    float xDelta_b = C.x - B.x;
    pt center = P(0,0);

    float aSlope = yDelta_a/xDelta_a;
    float bSlope = yDelta_b/xDelta_b;  
    center.x = (aSlope*bSlope*(A.y - C.y) + bSlope*(A.x + B.x)
        - aSlope*(B.x+C.x) )/(2* (bSlope-aSlope) );
    center.y = -1*(center.x - (A.x+B.x)/2)/aSlope +  (A.y+B.y)/2;

    return center;
  Geocache Thing Series:
  Helpful sites:
  So, I've had grand plans of figuring out a way to simply trilaterate a place between three points knowing only the distances from those points.  Also having become savvy with calculating distances between points using arc-lengths to account for the curvature of the earth, I though "Hey, I can do this…"  After a few hours of cranking out numbers, I realized that I was into a much bigger problem than originally expected and asked a few co-workers for some help.  Let's qualify; they are both Ph.D. Post-Grads – one a physicist and one an aeronautical engineer. They do this kind of thing for fun and when I first explained my problem, the physicist simply said he wouldn't touch it with a ten- foot pole.   He called it "Spherical Geometry" and said that most people still can't do it.  Now, the aeronautical engineer was not so easily turned away and has spent the better part of the last 8 weeks of free time popping out "big equations."  Needless to say, he hasn't gotten even close.
  So today, I pose a much-simplified situation of the problem, which occurs in the days of Gilgamesh (you know, when the Earth was still flat).  From a certain three locations, a fourth can be found.  That's where you'll find the cache.
  Thing #1:  N 45° 04.033 W 093° 03.667
  Thing #2:  N 45° 03.491 W 093° 04.787
  Thing #3:  N 45° 04.655 W 093° 04.569