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
parent
fd4abd5519
commit
d4d5ab578d
7
util.cpp
7
util.cpp
|
@ -225,6 +225,13 @@ Quaternion Quaternion::Inverse(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Quaternion Quaternion::ToThe(double p) {
|
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;
|
Quaternion r;
|
||||||
Vector axis = Vector::From(vx, vy, vz);
|
Vector axis = Vector::From(vx, vy, vz);
|
||||||
double theta = acos(w); // okay, since magnitude is 1, so -1 <= w <= 1
|
double theta = acos(w); // okay, since magnitude is 1, so -1 <= w <= 1
|
||||||
|
|
Loading…
Reference in New Issue