#include <colvartypes.h>
Public Member Functions | |
| quaternion (cvm::real const &x, cvm::real const &y, cvm::real const &z) | |
| Constructor from a 3-d vector. | |
| quaternion (cvm::real const qv[4]) | |
| Constructor component by component. | |
| quaternion (cvm::real const &q0i, cvm::real const &q1i, cvm::real const &q2i, cvm::real const &q3i) | |
| Constructor component by component. | |
| void | set_from_euler_angles (cvm::real const &phi_in, cvm::real const &theta_in, cvm::real const &psi_in) |
| quaternion () | |
| Default constructor. | |
| void | set (cvm::real const value=0.0) |
| Set all components to a scalar. | |
| void | reset () |
| Set all components to zero (null quaternion). | |
| void | reset_rotation () |
| Set the q0 component to 1 and the others to 0 (quaternion representing no rotation). | |
| cvm::real & | operator[] (int const &i) |
| Access the quaternion as a 4-d array (return a reference). | |
| cvm::real | operator[] (int const &i) const |
| Access the quaternion as a 4-d array (return a value). | |
| cvm::real | norm2 () const |
| Square norm of the quaternion. | |
| cvm::real | norm () const |
| Norm of the quaternion. | |
| cvm::quaternion | conjugate () const |
| Return the conjugate quaternion. | |
| void | operator *= (cvm::real const &a) |
| void | operator/= (cvm::real const &a) |
| void | set_positive () |
| void | operator+= (cvm::quaternion const &h) |
| void | operator-= (cvm::quaternion const &h) |
| cvm::rvector | get_vector () const |
| Return the vector component. | |
| cvm::rvector | rotate (cvm::rvector const &v) const |
| Rotate v through this quaternion (put it in the rotated reference frame). | |
| cvm::quaternion | rotate (cvm::quaternion const &Q2) const |
| Rotate Q2 through this quaternion (put it in the rotated reference frame). | |
| cvm::rmatrix | rotation_matrix () const |
| Return the 3x3 matrix associated to this quaternion. | |
| cvm::real | cos2 (cvm::quaternion const &q) const |
| Return the square cosine between the orientation associated to this quaternion and another. | |
| cvm::real | dist2 (cvm::quaternion const &Q2) const |
| Square distance from another quaternion on the 4-dimensional unit sphere: returns the square of the angle along the shorter of the two geodesics. | |
| cvm::quaternion | dist2_grad (cvm::quaternion const &Q2) const |
| void | match (cvm::quaternion &Q2) const |
| Choose the closest between Q2 and -Q2 and save it back. Not required for dist2() and dist2_grad(). | |
| cvm::real | inner (cvm::quaternion const &Q2) const |
| Inner product (as a 4-d vector) with Q2; requires match() if the largest overlap is looked for. | |
Static Public Member Functions | |
| size_t | output_width (size_t const &real_width) |
| Tell the number of characters required to print a quaternion, given that of a real number. | |
| cvm::quaternion | promote (cvm::rvector const &v) |
| Promote a 3-vector to a quaternion. | |
Public Attributes | |
| cvm::real | q0 |
| cvm::real | q1 |
| cvm::real | q2 |
| cvm::real | q3 |
Friends | |
| std::ostream & | operator<< (std::ostream &os, cvm::quaternion const &q) |
| Formatted output operator. | |
| std::istream & | operator>> (std::istream &is, cvm::quaternion &q) |
| Formatted input operator. | |
| cvm::quaternion | operator+ (cvm::quaternion const &h, cvm::quaternion const &q) |
| cvm::quaternion | operator- (cvm::quaternion const &h, cvm::quaternion const &q) |
| cvm::quaternion | operator * (cvm::quaternion const &h, cvm::quaternion const &q) |
Provides the quaternion product. NOTE: for the inner product use: h.inner (q); | |
| cvm::quaternion | operator * (cvm::real const &c, cvm::quaternion const &q) |
| cvm::quaternion | operator * (cvm::quaternion const &q, cvm::real const &c) |
| cvm::quaternion | operator/ (cvm::quaternion const &q, cvm::real const &c) |
Definition at line 552 of file colvartypes.h.
|
||||||||||||||||
|
Constructor from a 3-d vector.
Definition at line 559 of file colvartypes.h.
|
|
|
Constructor component by component.
Definition at line 564 of file colvartypes.h.
|
|
||||||||||||||||||||
|
Constructor component by component.
Definition at line 569 of file colvartypes.h.
|
|
|
Default constructor.
Definition at line 597 of file colvartypes.h. 00598 {
00599 reset();
00600 }
|
|
|
Return the conjugate quaternion.
Definition at line 681 of file colvartypes.h. 00682 {
00683 return cvm::quaternion (q0, -q1, -q2, -q3);
00684 }
|
|
|
Return the square cosine between the orientation associated to this quaternion and another.
Definition at line 802 of file colvartypes.h. References get_vector(), colvarmodule::rvector::norm2(), outer(), and rotate(). 00803 {
00804 // get a vector orthogonal to both axes of rotation
00805 cvm::rvector const op = (cvm::rvector::outer (this->get_vector(), q.get_vector()));
00806 cvm::real const opl2 = op.norm2();
00807 // rotate it with both quaternions and get the normalized inner product
00808 return ( (opl2 > 0.0) ?
00809 ((this->rotate (op)) * (q.rotate (op))) / opl2 :
00810 1.0 );
00811 }
|
|
|
Square distance from another quaternion on the 4-dimensional unit sphere: returns the square of the angle along the shorter of the two geodesics.
Definition at line 817 of file colvartypes.h. References PI, q0, q1, q2, and q3. Referenced by colvarvalue::dist2(), and simple_scalar_dist_functions(). 00818 {
00819 cvm::real const cos_omega = this->q0*Q2.q0 + this->q1*Q2.q1 +
00820 this->q2*Q2.q2 + this->q3*Q2.q3;
00821
00822 cvm::real const omega = ::acos ( (cos_omega > 1.0) ? 1.0 :
00823 ( (cos_omega < -1.0) ? -1.0 : cos_omega) );
00824
00825 // get the minimum distance: x and -x are the same quaternion
00826 if (cos_omega > 0.0)
00827 return omega * omega;
00828 else
00829 return (PI-omega) * (PI-omega);
00830 }
|
|
|
Gradient of the square distance: returns a 4-vector equivalent to the one provided by slerp Definition at line 834 of file colvartypes.h. References PI, q0, q1, q2, and q3. Referenced by colvarvalue::dist2_grad(), colvar::orientation::dist2_lgrad(), and colvar::orientation::dist2_rgrad(). 00835 {
00836 cvm::real const cos_omega = this->q0*Q2.q0 + this->q1*Q2.q1 + this->q2*Q2.q2 + this->q3*Q2.q3;
00837 cvm::real const omega = ::acos ( (cos_omega > 1.0) ? 1.0 :
00838 ( (cos_omega < -1.0) ? -1.0 : cos_omega) );
00839 cvm::real const sin_omega = ::sin (omega);
00840
00841 if (::fabs (sin_omega) < 1.0E-14) {
00842 // return a null 4d vector
00843 return cvm::quaternion (0.0, 0.0, 0.0, 0.0);
00844 }
00845
00846 cvm::quaternion const
00847 grad1 ((-1.0)*sin_omega*Q2.q0 + cos_omega*(this->q0-cos_omega*Q2.q0)/sin_omega,
00848 (-1.0)*sin_omega*Q2.q1 + cos_omega*(this->q1-cos_omega*Q2.q1)/sin_omega,
00849 (-1.0)*sin_omega*Q2.q2 + cos_omega*(this->q2-cos_omega*Q2.q2)/sin_omega,
00850 (-1.0)*sin_omega*Q2.q3 + cos_omega*(this->q3-cos_omega*Q2.q3)/sin_omega);
00851
00852 if (cos_omega > 0.0) {
00853 return 2.0*omega*grad1;
00854 }
00855 else {
00856 return -2.0*(PI-omega)*grad1;
00857 }
00858 }
|
|
|
Return the vector component.
Definition at line 720 of file colvartypes.h. Referenced by cos2(), and rotate(). 00721 {
00722 return cvm::rvector (q1, q2, q3);
00723 }
|
|
|
Inner product (as a 4-d vector) with Q2; requires match() if the largest overlap is looked for.
Definition at line 871 of file colvartypes.h. Referenced by operator *(). 00872 {
00873 cvm::real const prod = this->q0*Q2.q0 + this->q1*Q2.q1 +
00874 this->q2*Q2.q2 + this->q3*Q2.q3;
00875 return prod;
00876 }
|
|
|
Choose the closest between Q2 and -Q2 and save it back. Not required for dist2() and dist2_grad().
Definition at line 862 of file colvartypes.h. 00863 {
00864 cvm::real const cos_omega = this->q0*Q2.q0 + this->q1*Q2.q1 +
00865 this->q2*Q2.q2 + this->q3*Q2.q3;
00866 if (cos_omega < 0.0) Q2 *= -1.0;
00867 }
|
|
|
Norm of the quaternion.
Definition at line 675 of file colvartypes.h. 00676 {
00677 return ::sqrt (this->norm2());
00678 }
|
|
|
Square norm of the quaternion.
Definition at line 669 of file colvartypes.h. Referenced by colvarvalue::apply_constraints(), and colvarvalue::norm2().
|
|
|
Definition at line 686 of file colvartypes.h.
|
|
|
Definition at line 705 of file colvartypes.h. References q0, q1, q2, and q3.
|
|
|
Definition at line 709 of file colvartypes.h. References q0, q1, q2, and q3.
|
|
|
Definition at line 691 of file colvartypes.h.
|
|
|
Access the quaternion as a 4-d array (return a value).
Definition at line 651 of file colvartypes.h. References colvarmodule::fatal_error(). 00651 {
00652 switch (i) {
00653 case 0:
00654 return this->q0;
00655 case 1:
00656 return this->q1;
00657 case 2:
00658 return this->q2;
00659 case 3:
00660 return this->q3;
00661 default:
00662 cvm::fatal_error ("Error: trying to access a quaternion "
00663 "component which is not between 0 and 3.\n");
00664 return this->q0;
00665 }
00666 }
|
|
|
Access the quaternion as a 4-d array (return a reference).
Definition at line 634 of file colvartypes.h. References colvarmodule::fatal_error(). 00634 {
00635 switch (i) {
00636 case 0:
00637 return this->q0;
00638 case 1:
00639 return this->q1;
00640 case 2:
00641 return this->q2;
00642 case 3:
00643 return this->q3;
00644 default:
00645 cvm::fatal_error ("Error: incorrect quaternion component.\n");
00646 return q0;
00647 }
00648 }
|
|
|
Tell the number of characters required to print a quaternion, given that of a real number.
Definition at line 623 of file colvartypes.h. Referenced by colvarvalue::output_width(). 00624 {
00625 return 4*real_width + 13;
00626 }
|
|
|
Promote a 3-vector to a quaternion.
Definition at line 715 of file colvartypes.h. References colvarmodule::rvector::x, colvarmodule::rvector::y, and colvarmodule::rvector::z. 00716 {
00717 return cvm::quaternion (0.0, v.x, v.y, v.z);
00718 }
|
|
|
Set all components to zero (null quaternion).
Definition at line 609 of file colvartypes.h.
|
|
|
Set the q0 component to 1 and the others to 0 (quaternion representing no rotation).
Definition at line 616 of file colvartypes.h.
|
|
|
Rotate Q2 through this quaternion (put it in the rotated reference frame).
Definition at line 772 of file colvartypes.h. References get_vector(), q0, colvarmodule::rvector::x, colvarmodule::rvector::y, and colvarmodule::rvector::z. 00773 {
00774 cvm::rvector const vq_rot = this->rotate (Q2.get_vector());
00775 return cvm::quaternion (Q2.q0, vq_rot.x, vq_rot.y, vq_rot.z);
00776 }
|
|
|
Rotate v through this quaternion (put it in the rotated reference frame).
Definition at line 765 of file colvartypes.h. Referenced by colvar::rmsd::calc_gradients(), cos2(), and colvarmodule::rotation::rotate(). 00766 {
00767 return ((*this) * promote (v) * ((*this).conjugate())).get_vector();
00768 }
|
|
|
Return the 3x3 matrix associated to this quaternion.
Definition at line 779 of file colvartypes.h. References colvarmodule::rmatrix::xx(), colvarmodule::rmatrix::xy(), colvarmodule::rmatrix::xz(), colvarmodule::rmatrix::yx(), colvarmodule::rmatrix::yy(), colvarmodule::rmatrix::yz(), colvarmodule::rmatrix::zx(), colvarmodule::rmatrix::zy(), and colvarmodule::rmatrix::zz(). Referenced by colvarmodule::rotation::matrix(). 00780 {
00781 cvm::rmatrix R;
00782
00783 R.xx() = q0*q0 + q1*q1 - q2*q2 - q3*q3;
00784 R.yy() = q0*q0 - q1*q1 + q2*q2 - q3*q3;
00785 R.zz() = q0*q0 - q1*q1 - q2*q2 + q3*q3;
00786
00787 R.xy() = 2.0 * (q1*q2 - q0*q3);
00788 R.xz() = 2.0 * (q0*q2 + q1*q3);
00789
00790 R.yx() = 2.0 * (q0*q3 + q1*q2);
00791 R.yz() = 2.0 * (q2*q3 - q0*q1);
00792
00793 R.zx() = 2.0 * (q1*q3 - q0*q2);
00794 R.zy() = 2.0 * (q0*q1 + q2*q3);
00795
00796 return R;
00797 }
|
|
|
Set all components to a scalar.
Definition at line 603 of file colvartypes.h.
|
|
||||||||||||||||
|
"Constructor" after Euler angles (in radians) http://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles Definition at line 579 of file colvartypes.h. 00582 {
00583 q0 = ( (::cos (phi_in/2.0)) * (::cos (theta_in/2.0)) * (::cos (psi_in/2.0)) +
00584 (::sin (phi_in/2.0)) * (::sin (theta_in/2.0)) * (::sin (psi_in/2.0)) );
00585
00586 q1 = ( (::sin (phi_in/2.0)) * (::cos (theta_in/2.0)) * (::cos (psi_in/2.0)) -
00587 (::cos (phi_in/2.0)) * (::sin (theta_in/2.0)) * (::sin (psi_in/2.0)) );
00588
00589 q2 = ( (::cos (phi_in/2.0)) * (::sin (theta_in/2.0)) * (::cos (psi_in/2.0)) +
00590 (::sin (phi_in/2.0)) * (::cos (theta_in/2.0)) * (::sin (psi_in/2.0)) );
00591
00592 q3 = ( (::cos (phi_in/2.0)) * (::cos (theta_in/2.0)) * (::sin (psi_in/2.0)) -
00593 (::sin (phi_in/2.0)) * (::sin (theta_in/2.0)) * (::cos (psi_in/2.0)) );
00594 }
|
|
|
Definition at line 696 of file colvartypes.h. 00697 {
00698 if (q0 > 0.0) return;
00699 q0 = -q0;
00700 q1 = -q1;
00701 q2 = -q2;
00702 q3 = -q3;
00703 }
|
|
||||||||||||
|
Definition at line 751 of file colvartypes.h. 00753 {
00754 return cvm::quaternion (q.q0*c, q.q1*c, q.q2*c, q.q3*c);
00755 }
|
|
||||||||||||
|
Definition at line 746 of file colvartypes.h. 00748 {
00749 return cvm::quaternion (c*q.q0, c*q.q1, c*q.q2, c*q.q3);
00750 }
|
|
||||||||||||
|
Provides the quaternion product. NOTE: for the inner product use: h.inner (q);
Definition at line 738 of file colvartypes.h. 00739 {
00740 return cvm::quaternion (h.q0*q.q0 - h.q1*q.q1 - h.q2*q.q2 - h.q3*q.q3,
00741 h.q0*q.q1 + h.q1*q.q0 + h.q2*q.q3 - h.q3*q.q2,
00742 h.q0*q.q2 + h.q2*q.q0 + h.q3*q.q1 - h.q1*q.q3,
00743 h.q0*q.q3 + h.q3*q.q0 + h.q1*q.q2 - h.q2*q.q1);
00744 }
|
|
||||||||||||
|
Definition at line 726 of file colvartypes.h. 00727 {
00728 return cvm::quaternion (h.q0+q.q0, h.q1+q.q1, h.q2+q.q2, h.q3+q.q3);
00729 }
|
|
||||||||||||
|
Definition at line 731 of file colvartypes.h. 00732 {
00733 return cvm::quaternion (h.q0-q.q0, h.q1-q.q1, h.q2-q.q2, h.q3-q.q3);
00734 }
|
|
||||||||||||
|
Definition at line 756 of file colvartypes.h. 00758 {
00759 return cvm::quaternion (q.q0/c, q.q1/c, q.q2/c, q.q3/c);
00760 }
|
|
||||||||||||
|
Formatted output operator.
|
|
||||||||||||
|
Formatted input operator.
|
|
|
Definition at line 556 of file colvartypes.h. Referenced by dist2(), dist2_grad(), colvarvalue::inverse(), operator+=(), operator-=(), operator<<(), operator>>(), and rotate(). |
|
|
Definition at line 556 of file colvartypes.h. Referenced by dist2(), dist2_grad(), colvarvalue::inverse(), operator+=(), operator-=(), operator<<(), and operator>>(). |
|
|
Definition at line 556 of file colvartypes.h. Referenced by dist2(), dist2_grad(), colvarvalue::inverse(), operator+=(), operator-=(), operator<<(), and operator>>(). |
|
|
Definition at line 556 of file colvartypes.h. Referenced by dist2(), dist2_grad(), colvarvalue::inverse(), operator+=(), operator-=(), operator<<(), and operator>>(). |
1.3.9.1