Loading ...
Sorry, an error occurred while loading the content.

893Re: [tracker2] Distance calculation redux

Expand Messages
  • Wes Johnston, AI4PX
    Aug 30, 2006
    • 0 Attachment
      Although your way is probably faster (and close enough for government work), why not take the COS of the average latitude for figuring convergence?  It would require addition and division to get the average, a call to COS (which I assume you already have compiled in anyway) and a multiplication to apply the convergence (which you already do with your 8 bands method).
      I've checked the "flat earth" pythagorean theorem method using COS convergence out to 100 miles and it's off by less than 0.1 miles at 99miles.... and since most people only care about 2 significant digits, it's a great fit for a small processor.
      Sorry can't help with the arctan.

      On 8/30/06, scott@... <scott@...> wrote:

      My first attempt at a distance calculation (using a floating point
      implementation of the haversine formula) required 5 trigonometric function
      calls, two square roots, and several floating point divisions. It also
      needed 3 watchdog resets to keep the CPU from timing out during the
      calculation! Floating point math is NOT the HC08's strong suit.

      I rewrote it using mostly integer math, applying the pythagorean theorem and
      dividing each hemisphere into 8 latitude bands to compensate for the
      convergence of the meridians. I think it's accurate enough for this
      application, and it's pretty fast. It's got one square root call and no

      I also added the ability to use compressed mode with a fixed position. This
      was important because the distance calculation works from the compressed
      integer representation of the coordinates, so the conversion had to be done

      Something's still not quite right - two points with the same coordinates
      show a distance of 323 feet. Gotta track that one down. But it seems to be
      good enough for distances in miles - everything seems to be within about 10%
      of what it should be.

      I was thinking that a cool use for this would be to add a scripting option
      to trigger an action based on distance to a station. A T2 at your house
      could see your car coming and turn the driveway light on when it's within a
      mile, or your mobile station could turn on a proximity alarm light when you
      come within a certain distance of another station on the road.

      Now for bearing calculation. Anyone know how to fake an arctangent


    • Show all 8 messages in this topic