Support for directional data

Paul Harris paulharris at computer.org
Tue Oct 21 08:17:04 UTC 2008


2008/10/21 Sylvain Bougerel <sylvain.bougerel.devel at gmail.com>

> On Tue, Oct 21, 2008 at 2:18 PM, Paul Harris <paulharris at computer.org>
> wrote:
> > I agree, i just meant that the *current* kdtree uses euclidean distances
> > (right?), and that should be a template parameter.
> >
>
> The current uses euclidean distances.
>
> Besides there's something I wanted to know.
>
> Concerning the current euclidean distance calculation, in some cases,
> if you calculate a distance between some very far points, it might
> overflow and it would return a distance that is really wrong.
>
>
> http://www.gnu.org/software/gsl/manual/gsl-ref.html#index-euclidean-distance-function_002c-hypot-90
>
> The link above points to a function that calculates distance in a way
> that avoids overflow (!):
>
> double
> gsl_hypot3(const double x, const double y, const double z)
> {
>  double xabs = fabs(x);
>  double yabs = fabs(y);
>  double zabs = fabs(z);
>  double w = GSL_MAX(xabs, GSL_MAX(yabs, zabs));
>
>  if (w == 0.0)
>    {
>      return (0.0);
>    }
>  else
>    {
>      double r = w * sqrt((xabs / w) * (xabs / w) +
>                          (yabs / w) * (yabs / w) +
>                          (zabs / w) * (zabs / w));
>      return r;
>    }
> }
>
>
> I think we should do it this way too, but it only supports "float" and
> "double". Therefore, should we only provide a distance function for
> the type "float" and "double"?
>
> Also take not that it's a really slow calculation (because of all the
> division).
>
> Any suggestion concerning the other distance calculation that we should
> include?
>
>

This is very interesting although not applicable to my environment ...
If you can catch double/float overflows (or at least check for them), then
you could do the simple calculation first, and if it overflows, then do the
slow version.

It could be included along with kdtree as an alternative distance calc that
users can just plug into the template.  ditto for any others that the
current users have managed to figure out.

maybe follow up with the guy who was doing the
distance-on-the-surface-of-the-earth?  and other guys like him?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.alioth.debian.org/pipermail/libkdtree-devel/attachments/20081021/4399b77a/attachment.htm 


More information about the libkdtree-devel mailing list