Commit f180deb2 authored by David Bommes's avatar David Bommes
Browse files

added range clamping

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@8030 383ad7c9-94d9-4d36-a494-682f7c89f535
parent a462c79c
......@@ -287,25 +287,22 @@ public:
/// quaternion logarithm (for unit quaternions)
Quaternion logarithm() const
{
if( W > 1.0 || W < -1.0)
{
std::cerr << "Warning: invalid input to quaternion logarithm W should lie within [-1,1]: "
<< W << std::endl;
}
else
{
Scalar theta_half = acos(W);
// clamp to valid input
double w = W;
if( w > 1.0) w = 1.0;
else if( w < -1.0) w = -1.0;
Vec3 n(X,Y,Z);
Scalar n_norm( n.norm());
Scalar theta_half = acos(w);
if( n_norm > 1e-6 )
n *= theta_half/n_norm;
else
n = Vec3(0,0,0);
Vec3 n(X,Y,Z);
Scalar n_norm( n.norm());
if( n_norm > 1e-6 )
n *= theta_half/n_norm;
else
n = Vec3(0,0,0);
return Quaternion( 0, n[0], n[1], n[2]);
}
return Quaternion( 0, n[0], n[1], n[2]);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment