34 value_type coshalfangle = cos( 0.5*tempAngle );
35 value_type sinhalfangle = sin( 0.5*tempAngle );
37 theVector[0] =
x * sinhalfangle * inversenorm;
38 theVector[1] =
y * sinhalfangle * inversenorm;
39 theVector[2] = z * sinhalfangle * inversenorm;
40 theVector[3] = coshalfangle;
66 makeRotate(
ossimDpt3d(vec1[0], vec1[1], vec1[2]),
101 if ((fromLen2 < 1.0-1e-7) || (fromLen2 > 1.0+1e-7))
103 fromLen = sqrt(fromLen2);
104 sourceVector /= fromLen;
109 if ((toLen2 < 1.0-1e-7) || (toLen2 > 1.0+1e-7))
113 if ((toLen2 > fromLen2-1e-7) && (toLen2 < fromLen2+1e-7))
117 else toLen = sqrt(toLen2);
118 targetVector /= toLen;
123 double dotProdPlus1 = 1.0 + sourceVector * targetVector;
126 if (dotProdPlus1 < 1e-7) {
132 if (fabs(sourceVector.
x) < 0.6) {
133 const double norm = sqrt(1.0 - sourceVector.
x * sourceVector.
x);
135 theVector[1] = sourceVector.
z / norm;
136 theVector[2] = -sourceVector.
y / norm;
138 }
else if (fabs(sourceVector.
y) < 0.6) {
139 const double norm = sqrt(1.0 - sourceVector.
y * sourceVector.
y);
140 theVector[0] = -sourceVector.
z / norm;
142 theVector[2] = sourceVector.
x / norm;
145 const double norm = sqrt(1.0 - sourceVector.
z * sourceVector.
z);
146 theVector[0] = sourceVector.
y / norm;
147 theVector[1] = -sourceVector.
x / norm;
156 const double s = sqrt(0.5 * dotProdPlus1);
157 const ossimDpt3d tmp = sourceVector ^ targetVector / (2.0*s);
158 theVector[0] = tmp.
x;
159 theVector[1] = tmp.
y;
160 theVector[2] = tmp.
z;
247 value_type sinhalfangle = sqrt( theVector[0]*theVector[0] + theVector[1]*theVector[1] + theVector[2]*theVector[2] );
249 angle = 2.0 * atan2( sinhalfangle, theVector[3] );
252 x = theVector[0] / sinhalfangle;
253 y = theVector[1] / sinhalfangle;
254 z = theVector[2] / sinhalfangle;
273 const double epsilon = 0.00001;
274 double omega, cosomega, sinomega, scale_from, scale_to ;
276 osg::Quat quatTo(to);
279 cosomega = from.asVec4() * to.asVec4();
283 cosomega = -cosomega;
287 if( (1.0 - cosomega) > epsilon )
289 omega= acos(cosomega) ;
290 sinomega = sin(omega) ;
292 scale_from = sin((1.0-t)*omega)/sinomega ;
293 scale_to = sin(t*omega)/sinomega ;
302 scale_from = 1.0 - t ;
306 *
this = (from*scale_from) + (quatTo*scale_to);
void slerp(value_type t, const Quaternion &from, const Quaternion &to)
Spherical Linear Interpolation.
ossim::Quaternion getRotate() const
double radiansToDegrees(double x)
void makeRotate(const ossim::Quaternion &quat)
double degreesToRadians(double x)
void set(value_type x, value_type y, value_type z, value_type w)
void getRotate(value_type &angle, value_type &x, value_type &y, value_type &z) const
Return the angle and vector components represented by the quaternion.
void makeRotate(value_type angle, value_type x, value_type y, value_type z)
Set the elements of the Quat to represent a rotation of angle (radians) around the axis (x...
void get(ossimMatrix4x4 &matrix) const