63 v[0] = internal_data[0];
64 v[1] = internal_data[1];
65 v[2] = internal_data[2];
66 v[3] = internal_data[3];
72 return internal_data[0];
77 return internal_data[1];
82 return internal_data[2];
87 return internal_data[3];
92 return internal_data[0];
97 return internal_data[1];
102 return internal_data[2];
107 return internal_data[3];
115 bool ok = connection.
expectBlock((
char*)&header,
sizeof(header));
116 if (!ok)
return false;
140 connection.
appendBlock((
char*)&header,
sizeof(header));
158 yCError(QUATERNION,
"fromRotationMatrix() failed, matrix should be >= 3x3");
162 double tr = R(0, 0) + R(1, 1) + R(2, 2);
166 double sqtrp1 = sqrt(tr + 1.0);
167 double sqtrp12 = 2.0*sqtrp1;
168 internal_data[0] = 0.5*sqtrp1;
169 internal_data[1] = (R(2, 1) - R(1, 2)) / sqtrp12;
170 internal_data[2] = (R(0, 2) - R(2, 0)) / sqtrp12;
171 internal_data[3] = (R(1, 0) - R(0, 1)) / sqtrp12;
173 else if ((R(1, 1)>R(0, 0)) && (R(1, 1)>R(2, 2)))
175 double sqdip1 = sqrt(R(1, 1) - R(0, 0) - R(2, 2) + 1.0);
176 internal_data[2] = 0.5*sqdip1;
179 sqdip1 = 0.5 / sqdip1;
181 internal_data[0] = (R(0, 2) - R(2, 0))*sqdip1;
182 internal_data[1] = (R(1, 0) + R(0, 1))*sqdip1;
183 internal_data[3] = (R(2, 1) + R(1, 2))*sqdip1;
185 else if (R(2, 2)>R(0, 0))
187 double sqdip1 = sqrt(R(2, 2) - R(0, 0) - R(1, 1) + 1.0);
188 internal_data[3] = 0.5*sqdip1;
191 sqdip1 = 0.5 / sqdip1;
193 internal_data[0] = (R(1, 0) - R(0, 1))*sqdip1;
194 internal_data[1] = (R(0, 2) + R(2, 0))*sqdip1;
195 internal_data[2] = (R(2, 1) + R(1, 2))*sqdip1;
199 double sqdip1 = sqrt(R(0, 0) - R(1, 1) - R(2, 2) + 1.0);
200 internal_data[1] = 0.5*sqdip1;
203 sqdip1 = 0.5 / sqdip1;
205 internal_data[0] = (R(2, 1) - R(1, 2))*sqdip1;
206 internal_data[2] = (R(1, 0) + R(0, 1))*sqdip1;
207 internal_data[3] = (R(0, 2) + R(2, 0))*sqdip1;
217 R(0, 0) = qin[0] * qin[0] + qin[1] * qin[1] - qin[2] * qin[2] - qin[3] * qin[3];
218 R(1, 0) = 2.0*(qin[1] * qin[2] + qin[0] * qin[3]);
219 R(2, 0) = 2.0*(qin[1] * qin[3] - qin[0] * qin[2]);
220 R(0, 1) = 2.0*(qin[1] * qin[2] - qin[0] * qin[3]);
221 R(1, 1) = qin[0] * qin[0] - qin[1] * qin[1] + qin[2] * qin[2] - qin[3] * qin[3];
222 R(2, 1) = 2.0*(qin[2] * qin[3] + qin[0] * qin[1]);
223 R(0, 2) = 2.0*(qin[1] * qin[3] + qin[0] * qin[2]);
224 R(1, 2) = 2.0*(qin[2] * qin[3] - qin[0] * qin[1]);
225 R(2, 2) = qin[0] * qin[0] - qin[1] * qin[1] - qin[2] * qin[2] + qin[3] * qin[3];
236 R(0, 0) = qin[0] * qin[0] + qin[1] * qin[1] - qin[2] * qin[2] - qin[3] * qin[3];
237 R(1, 0) = 2.0*(qin[1] * qin[2] + qin[0] * qin[3]);
238 R(2, 0) = 2.0*(qin[1] * qin[3] - qin[0] * qin[2]);
239 R(0, 1) = 2.0*(qin[1] * qin[2] - qin[0] * qin[3]);
240 R(1, 1) = qin[0] * qin[0] - qin[1] * qin[1] + qin[2] * qin[2] - qin[3] * qin[3];
241 R(2, 1) = 2.0*(qin[2] * qin[3] + qin[0] * qin[1]);
242 R(0, 2) = 2.0*(qin[1] * qin[3] + qin[0] * qin[2]);
243 R(1, 2) = 2.0*(qin[2] * qin[3] - qin[0] * qin[1]);
244 R(2, 2) = qin[0] * qin[0] - qin[1] * qin[1] - qin[2] * qin[2] + qin[3] * qin[3];
255 sprintf(tmp,
"w=% .*lf\t", precision, internal_data[0]);
ret += tmp;
256 sprintf(tmp,
"x=% .*lf\t", precision, internal_data[1]);
ret += tmp;
257 sprintf(tmp,
"y=% .*lf\t", precision, internal_data[2]);
ret += tmp;
258 sprintf(tmp,
"z=% .*lf\t", precision, internal_data[3]);
ret += tmp;
262 sprintf(tmp,
"w=% *.*lf ", width, precision, internal_data[0]);
ret += tmp;
263 sprintf(tmp,
"x=% *.*lf ", width, precision, internal_data[1]);
ret += tmp;
264 sprintf(tmp,
"y=% *.*lf ", width, precision, internal_data[2]);
ret += tmp;
265 sprintf(tmp,
"z=% *.*lf ", width, precision, internal_data[3]);
ret += tmp;
268 return ret.substr(0,
ret.length() - 1);
276 this->internal_data[0] = q.internal_data[0];
277 this->internal_data[1] = q.internal_data[1];
278 this->internal_data[2] = q.internal_data[2];
279 this->internal_data[3] = q.internal_data[3];
285 v.
resize(4); v[4] = angle;
289 this->internal_data[0] = q.internal_data[0];
290 this->internal_data[1] = q.internal_data[1];
291 this->internal_data[2] = q.internal_data[2];
292 this->internal_data[3] = q.internal_data[3];
304 return sqrt(internal_data[0] * internal_data[0] +
305 internal_data[1] * internal_data[1] +
306 internal_data[2] * internal_data[2] +
307 internal_data[3] * internal_data[3]);
312 double length =
abs();
313 internal_data[0] /= length;
314 internal_data[1] /= length;
315 internal_data[2] /= length;
316 internal_data[3] /= length;
322 return atan2(sqrt(internal_data[1] * internal_data[1] +
323 internal_data[2] * internal_data[2] +
324 internal_data[3] * internal_data[3]),
331 return Quaternion(internal_data[0], -internal_data[1], -internal_data[2], -internal_data[3]);