42 |
|
#include <math.h> |
43 |
|
#include "primitives/RigidBody.hpp" |
44 |
|
#include "utils/simError.h" |
45 |
+ |
#include "utils/NumericConstant.hpp" |
46 |
|
namespace oopse { |
47 |
|
|
48 |
|
RigidBody::RigidBody() : StuntDouble(otRigidBody, &Snapshot::rigidbodyData), inertiaTensor_(0.0){ |
275 |
|
dAtom = (DirectionalAtom *) atoms_[i]; |
276 |
|
dAtom->setA(a * refOrients_[i]); |
277 |
|
//dAtom->rotateBy( A ); |
278 |
+ |
} |
279 |
+ |
|
280 |
+ |
} |
281 |
+ |
|
282 |
+ |
} |
283 |
+ |
|
284 |
+ |
|
285 |
+ |
void RigidBody::updateAtoms(int frame) { |
286 |
+ |
unsigned int i; |
287 |
+ |
Vector3d ref; |
288 |
+ |
Vector3d apos; |
289 |
+ |
DirectionalAtom* dAtom; |
290 |
+ |
Vector3d pos = getPos(frame); |
291 |
+ |
RotMat3x3d a = getA(frame); |
292 |
+ |
|
293 |
+ |
for (i = 0; i < atoms_.size(); i++) { |
294 |
+ |
|
295 |
+ |
ref = body2Lab(refCoords_[i], frame); |
296 |
+ |
|
297 |
+ |
apos = pos + ref; |
298 |
+ |
|
299 |
+ |
atoms_[i]->setPos(apos, frame); |
300 |
+ |
|
301 |
+ |
if (atoms_[i]->isDirectional()) { |
302 |
+ |
|
303 |
+ |
dAtom = (DirectionalAtom *) atoms_[i]; |
304 |
+ |
dAtom->setA(a * refOrients_[i], frame); |
305 |
|
} |
306 |
|
|
307 |
|
} |
308 |
|
|
309 |
|
} |
310 |
|
|
311 |
+ |
void RigidBody::updateAtomVel() { |
312 |
+ |
Mat3x3d skewMat;; |
313 |
|
|
314 |
+ |
Vector3d ji = getJ(); |
315 |
+ |
Mat3x3d I = getI(); |
316 |
+ |
|
317 |
+ |
skewMat(0, 0) =0; |
318 |
+ |
skewMat(0, 1) = ji[2] /I(2, 2); |
319 |
+ |
skewMat(0, 2) = -ji[1] /I(1, 1); |
320 |
+ |
|
321 |
+ |
skewMat(1, 0) = -ji[2] /I(2, 2); |
322 |
+ |
skewMat(1, 1) = 0; |
323 |
+ |
skewMat(1, 2) = ji[0]/I(0, 0); |
324 |
+ |
|
325 |
+ |
skewMat(2, 0) =ji[1] /I(1, 1); |
326 |
+ |
skewMat(2, 1) = -ji[0]/I(0, 0); |
327 |
+ |
skewMat(2, 2) = 0; |
328 |
+ |
|
329 |
+ |
Mat3x3d mat = (getA() * skewMat).transpose(); |
330 |
+ |
Vector3d rbVel = getVel(); |
331 |
+ |
|
332 |
+ |
|
333 |
+ |
Vector3d velRot; |
334 |
+ |
for (int i =0 ; i < refCoords_.size(); ++i) { |
335 |
+ |
atoms_[i]->setVel(rbVel + mat * refCoords_[i]); |
336 |
+ |
} |
337 |
+ |
|
338 |
+ |
} |
339 |
+ |
|
340 |
+ |
void RigidBody::updateAtomVel(int frame) { |
341 |
+ |
Mat3x3d skewMat;; |
342 |
+ |
|
343 |
+ |
Vector3d ji = getJ(frame); |
344 |
+ |
Mat3x3d I = getI(); |
345 |
+ |
|
346 |
+ |
skewMat(0, 0) =0; |
347 |
+ |
skewMat(0, 1) = ji[2] /I(2, 2); |
348 |
+ |
skewMat(0, 2) = -ji[1] /I(1, 1); |
349 |
+ |
|
350 |
+ |
skewMat(1, 0) = -ji[2] /I(2, 2); |
351 |
+ |
skewMat(1, 1) = 0; |
352 |
+ |
skewMat(1, 2) = ji[0]/I(0, 0); |
353 |
+ |
|
354 |
+ |
skewMat(2, 0) =ji[1] /I(1, 1); |
355 |
+ |
skewMat(2, 1) = -ji[0]/I(0, 0); |
356 |
+ |
skewMat(2, 2) = 0; |
357 |
+ |
|
358 |
+ |
Mat3x3d mat = (getA(frame) * skewMat).transpose(); |
359 |
+ |
Vector3d rbVel = getVel(frame); |
360 |
+ |
|
361 |
+ |
|
362 |
+ |
Vector3d velRot; |
363 |
+ |
for (int i =0 ; i < refCoords_.size(); ++i) { |
364 |
+ |
atoms_[i]->setVel(rbVel + mat * refCoords_[i], frame); |
365 |
+ |
} |
366 |
+ |
|
367 |
+ |
} |
368 |
+ |
|
369 |
+ |
|
370 |
+ |
|
371 |
|
bool RigidBody::getAtomPos(Vector3d& pos, unsigned int index) { |
372 |
|
if (index < atoms_.size()) { |
373 |
|
|
511 |
|
simError(); |
512 |
|
} |
513 |
|
|
514 |
< |
euler[0] = ats->getEulerPhi(); |
515 |
< |
euler[1] = ats->getEulerTheta(); |
516 |
< |
euler[2] = ats->getEulerPsi(); |
514 |
> |
euler[0] = ats->getEulerPhi() * NumericConstant::PI /180.0; |
515 |
> |
euler[1] = ats->getEulerTheta() * NumericConstant::PI /180.0; |
516 |
> |
euler[2] = ats->getEulerPsi() * NumericConstant::PI /180.0; |
517 |
|
|
518 |
|
RotMat3x3d Atmp(euler); |
519 |
|
refOrients_.push_back(Atmp); |