jenetics / jpx

JPX - Java GPX library
Apache License 2.0
202 stars 30 forks source link

Make distance calculation more stable #134

Closed jenetics closed 3 years ago

jenetics commented 3 years ago

The current implementation for calculating the distance between two points contains code, where values are checked against zero.

// Eq. 17 Careful! sin2sigma might be almost 0!
final double sinalpha = sin2sigma == 0.0
    ? 0.0
    : cosU1cosU2*sinlambda/sinsigma;

This kind of comparison isn't numerically stable. Replace this code with an epsilon check.

jenetics commented 3 years ago

Merged into r2.1.0 branch.