Skip to content
Snippets Groups Projects
Commit c3c58400 authored by Oliver Sander's avatar Oliver Sander Committed by sander@PCPOOL.MI.FU-BERLIN.DE
Browse files

make sure arccos _never_ gets a value >1, because that leads to NaN

[[Imported from SVN: r5576]]
parent 7b308286
No related branches found
No related tags found
No related merge requests found
......@@ -35,7 +35,16 @@ public:
/** \brief Length of the great arc connecting the two points */
static double distance(const UnitVector& a, const UnitVector& b) {
return std::acos(a.data_ * b.data_);
// Not nice: we are in a class for unit vectors, but the class is actually
// supposed to handle perturbations of unit vectors as well. Therefore
// we normalize here.
double x = a.data_ * b.data_/a.data_.two_norm()/b.data_.two_norm();
// paranoia: if the argument is just eps larger than 1 acos returns NaN
x = std::min(x,1.0);
return std::acos(x);
}
/** \brief Compute the gradient of the squared distance function keeping the first argument fixed
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment