[PATCH] Simplify distance calculations
Robert C. Helling
helling at atdotde.de
Sat Jun 13 00:06:38 PDT 2015
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
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 495 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://lists.subsurface-divelog.org/pipermail/subsurface/attachments/20150613/c7dfc24e/attachment.sig>
More information about the subsurface
mailing list