[PATCH] Simplify distance calculations

Rick Walsh rickmwalsh at gmail.com
Sat Jun 13 00:20:46 PDT 2015


On 13 Jun 2015 5:06 pm, "Robert C. Helling" <helling at atdotde.de> wrote:
>
>
> On 13 Jun 2015, at 08:53, Linus Torvalds <torvalds at linux-foundation.org>
wrote:
>
> > On Fri, Jun 12, 2015 at 2:34 PM, Anton Lundin <glance at acc.umu.se> wrote:
> >>
> >> Sorry, One _degree_ in latitude is about 111.5 km where i live, and
> >> thats the basis for the convertion that 10 udeg is about a meter.
> >>
> >>> +     return sqrt(lat1.udeg*lat2.udeg + lon1.udeg*lon2.udeg) / 10;
> >
> > Ugh. I think that's a bit *too* simplified.
> >
> > You do want to have that multiplication with "cos(latitude)" because
> > longitude lines are much further apart around the equator than in
> > temperate areas..
> >
> > And don't you want to square the *differences* (with that latitude
> > correction) rather than just multiply the lat/long pairwise together?
> > That just looks insane.The distance from 0,0 to any other point is
> > always zero? That's an interesting distance function.
> >
> > I guess there are few divesites where we need to worry about
> > wraparound (much less 20 m apart), so those kinds of simplifications I
> > can see, but you seem to have gone a bit overboard.
> >
>
> A somewhat simplified formula that saves a bit of trigonometry but deals
correctly with wrap around and the fact that meridians have a distance
proportional to cos(latitude) would be
>
> sin(lon1-lon2)^2 * cos(lat1)^2 + sin(lat1-lat2)^2 < distance^2 /
radius_of_earth^2

You could even save more trig and take advantage of the fact that sin(a) =
~a, for small a (in radians).

((lon1-lon2)×pi/180)^2 * cos(lat1)^2 + ((lat1-lat2)×pi/180)^2 < distance^2
/ radius_of_earth^2

I'm not a programmer but I assume multiplying by pi/180 = 0.0175 is less
expensive than sine

>
> This should be fine for distances much smaller than the radius of the
earth. The right hand side is a constant known at compile time, so it
should be figured out by the compiler already.
>
> Best
> Robert
>
> --
>
.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oO
> Robert C. Helling     Elite Master Course Theoretical and Mathematical
Physics
>                       Scientific Coordinator
>                       Ludwig Maximilians Universitaet Muenchen, Dept.
Physik
> print "Just another   Phone: +49 89 2180-4523  Theresienstr. 39, rm. B339
>     stupid .sig\n";   http://www.atdotde.de
>
>
> _______________________________________________
> subsurface mailing list
> subsurface at subsurface-divelog.org
> http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.subsurface-divelog.org/pipermail/subsurface/attachments/20150613/7f0472da/attachment.html>


More information about the subsurface mailing list