Add a special case when raising quaternions almost equal to

(+/-1, 0, 0, 0) to some power; that was failing if the magnitude of
w was slightly greater than 1, so that acos() returned NaN.

[git-p4: depot-paths = "//depot/solvespace/": change = 1820]
solver
Jonathan Westhues 2008-07-02 01:52:32 -08:00
parent fd4abd5519
commit d4d5ab578d
1 changed files with 7 additions and 0 deletions

View File

@ -225,6 +225,13 @@ Quaternion Quaternion::Inverse(void) {
}
Quaternion Quaternion::ToThe(double p) {
// Avoid division by zero, or arccos of something not in its domain
if(w >= (1 - 1e-6)) {
return From(1, 0, 0, 0);
} else if(w <= (-1 + 1e-6)) {
return From(-1, 0, 0, 0);
}
Quaternion r;
Vector axis = Vector::From(vx, vy, vz);
double theta = acos(w); // okay, since magnitude is 1, so -1 <= w <= 1