preserve length of rotation axis
This commit is contained in:
@@ -119,9 +119,11 @@ void Rotation::evaluateVector()
|
||||
double rfAngle = double(acos(this->quat[3])) * 2.0;
|
||||
double scale = (double)sin(rfAngle / 2.0);
|
||||
// Get a normalized vector
|
||||
this->_axis.x = this->quat[0] / scale;
|
||||
this->_axis.y = this->quat[1] / scale;
|
||||
this->_axis.z = this->quat[2] / scale;
|
||||
double l = this->_axis.Length();
|
||||
if (l < Base::Vector3d::epsilon()) l = 1;
|
||||
this->_axis.x = this->quat[0] * l / scale;
|
||||
this->_axis.y = this->quat[1] * l / scale;
|
||||
this->_axis.z = this->quat[2] * l / scale;
|
||||
|
||||
_angle = rfAngle;
|
||||
if (_angle >= D_PI) {
|
||||
@@ -146,7 +148,16 @@ void Rotation::setValue(const double q0, const double q1, const double q2, const
|
||||
|
||||
void Rotation::getValue(Vector3d & axis, double & rfAngle) const
|
||||
{
|
||||
rfAngle = _angle;//double(acos(this->quat[3])) * 2.0;
|
||||
rfAngle = _angle;
|
||||
axis.x = _axis.x;
|
||||
axis.y = _axis.y;
|
||||
axis.z = _axis.z;
|
||||
axis.Normalize();
|
||||
}
|
||||
|
||||
void Rotation::getRawValue(Vector3d & axis, double & rfAngle) const
|
||||
{
|
||||
rfAngle = _angle;
|
||||
axis.x = _axis.x;
|
||||
axis.y = _axis.y;
|
||||
axis.z = _axis.z;
|
||||
@@ -242,13 +253,17 @@ void Rotation::setValue(const Vector3d & axis, const double fAngle)
|
||||
double l = norm.Length();
|
||||
// Keep old axis in case the new axis is the null vector
|
||||
if (l > 0.5) {
|
||||
this->_axis = norm;
|
||||
this->_axis = axis;
|
||||
}
|
||||
else {
|
||||
norm = _axis;
|
||||
norm.Normalize();
|
||||
}
|
||||
|
||||
double scale = (double)sin(theAngle/2.0);
|
||||
this->quat[0] = this->_axis.x * scale;
|
||||
this->quat[1] = this->_axis.y * scale;
|
||||
this->quat[2] = this->_axis.z * scale;
|
||||
this->quat[0] = norm.x * scale;
|
||||
this->quat[1] = norm.y * scale;
|
||||
this->quat[2] = norm.z * scale;
|
||||
}
|
||||
|
||||
void Rotation::setValue(const Vector3d & rotateFrom, const Vector3d & rotateTo)
|
||||
@@ -642,3 +657,11 @@ void Rotation::getYawPitchRoll(double& y, double& p, double& r) const
|
||||
p = (p/D_PI)*180;
|
||||
r = (r/D_PI)*180;
|
||||
}
|
||||
|
||||
bool Rotation::isNull() const
|
||||
{
|
||||
return (this->quat[0] == 0 &&
|
||||
this->quat[1] == 0 &&
|
||||
this->quat[2] == 0 &&
|
||||
this->quat[3] == 0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user