22 using namespace Marble;
24 Quaternion::Quaternion()
30 Quaternion::Quaternion(qreal w, qreal x, qreal y, qreal z)
38 Quaternion Quaternion::fromSpherical(qreal lon, qreal lat)
41 const qreal x = cos(lat) * sin(lon);
42 const qreal y = sin(lat);
43 const qreal z = cos(lat) * cos(lon);
48 void Quaternion::getSpherical(qreal &lon, qreal &lat)
const
59 lon = atan2(v[
Q_X], v[
Q_Z]);
66 (*this) *= 1.0 / length();
69 qreal Quaternion::length()
const
76 (*this) = (*this) * mult;
91 double const qlen = length();
93 double const a = acos(v[
Q_W]/qlen) / vlen;
100 double const s = std::exp(v[
Q_W]);
101 double const a = s * sin(vlen) / vlen;
105 Quaternion Quaternion::fromEuler(qreal pitch, qreal yaw, qreal roll)
107 const qreal cPhi = cos(0.5 * pitch);
108 const qreal cThe = cos(0.5 * yaw);
109 const qreal cPsi = cos(0.5 * roll);
111 const qreal sPhi = sin(0.5 * pitch);
112 const qreal sThe = sin(0.5 * yaw);
113 const qreal sPsi = sin(0.5 * roll);
115 const qreal w = cPhi * cThe * cPsi + sPhi * sThe * sPsi;
116 const qreal x = sPhi * cThe * cPsi - cPhi * sThe * sPsi;
117 const qreal y = cPhi * sThe * cPsi + sPhi * cThe * sPsi;
118 const qreal z = cPhi * cThe * sPsi - sPhi * sThe * cPsi;
123 qreal Quaternion::pitch() const
126 ( 1.0 - 2.0*(v[
Q_X]*v[
Q_X]+v[Q_Z]*v[Q_Z]) ) );
129 qreal Quaternion::yaw() const
132 ( 1.0 - 2.0*(v[
Q_Y]*v[
Q_Y]+v[Q_Z]*v[Q_Z]) ) );
135 qreal Quaternion::roll() const
140 #ifndef QT_NO_DEBUG_STREAM
143 QString quatdisplay =
QString(
"Quaternion: w= %1, x= %2, y= %3, z= %4, |q|= %5" )
146 debug << quatdisplay;
154 (*this) = (*this) * q;
207 qreal cosAlpha = ( q1.
v[
Q_X] * q2.
v[
Q_X]
211 qreal alpha = acos( cosAlpha );
212 qreal sinAlpha = sin( alpha );
214 if ( sinAlpha > 0.0 ) {
215 p1 = sin( ( 1.0 - t ) * alpha ) / sinAlpha;
216 p2 = sin( t * alpha ) / sinAlpha;
223 const qreal w = p1 * q1.
v[
Q_W] + p2 * q2.
v[
Q_W];
224 const qreal x = p1 * q1.
v[
Q_X] + p2 * q2.
v[
Q_X];
225 const qreal y = p1 * q1.
v[
Q_Y] + p2 * q2.
v[
Q_Y];
226 const qreal z = p1 * q1.
v[
Q_Z] + p2 * q2.
v[
Q_Z];
233 const qreal p1 = 1.0 - t;
235 const qreal w = p1 * q1.
v[
Q_W] + t * q2.
v[
Q_W];
236 const qreal x = p1 * q1.
v[
Q_X] + t * q2.
v[
Q_X];
237 const qreal y = p1 * q1.
v[
Q_Y] + t * q2.
v[
Q_Y];
238 const qreal z = p1 * q1.
v[
Q_Z] + t * q2.
v[
Q_Z];
246 void Quaternion::toMatrix(
matrix &m)
const
253 m[0][0] = 1.0 - 2.0 * (yy + zz);
254 m[0][1] = 2.0 * (xy + zw);
255 m[0][2] = 2.0 * (xz - yw);
258 const qreal xx = v[
Q_X] * v[
Q_X];
259 const qreal xw = v[
Q_X] * v[
Q_W];
260 const qreal yz = v[
Q_Y] * v[
Q_Z];
262 m[1][0] = 2.0 * (xy - zw);
263 m[1][1] = 1.0 - 2.0 * (xx + zz);
264 m[1][2] = 2.0 * (yz + xw);
267 m[2][0] = 2.0 * (xz + yw);
268 m[2][1] = 2.0 * (yz - xw);
269 m[2][2] = 1.0 - 2.0 * (xx + yy);
273 void Quaternion::rotateAroundAxis(
const matrix &m)
275 const qreal x = m[0][0] * v[
Q_X] + m[1][0] * v[
Q_Y] + m[2][0] * v[
Q_Z];
276 const qreal y = m[0][1] * v[
Q_X] + m[1][1] * v[
Q_Y] + m[2][1] * v[
Q_Z];
277 const qreal z = m[0][2] * v[
Q_X] + m[1][2] * v[
Q_Y] + m[2][2] * v[
Q_Z];
QDebug operator<<(QDebug debug, const Quaternion &q)
bool operator==(const DownloadPolicyKey &lhs, const DownloadPolicyKey &rhs)
Vec3 operator+(const Vec3 &c1, const Vec3 &c2)
void normalize(const QString &output)
Vec3 operator*(double r, const Vec3 &c1)
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const