COSMOS core  1.0.2 (beta)
Comprehensive Open-architecture Solution for Mission Operations Systems
Cosmos::Math::Quaternions Namespace Reference

Classes

class  Quaternion
 

Functions

Quaternion operator* (const Vectors::Vector &v, const Quaternion &q)
 
std::ostream & operator<< (std::ostream &os, const Quaternion &q)
 Scalar division. More...
 
Quaternion operator* (double scale, const Quaternion &q)
 Reverse scalar product. More...
 
Quaternion drotate_between (Vectors::Vector a, Vectors::Vector b)
 
Quaternion irotate_for (Vectors::Vector sourcea, Vectors::Vector sourceb, Vectors::Vector targeta, Vectors::Vector targetb)
 Create irotate quaternion from two orthogonal vectors. More...
 
Quaternion drotate_around_x (double angle)
 Rotation Quaternion for X axis. More...
 
Quaternion drotate_around_y (double angle)
 Rotation Quaternion for Y axis. More...
 
Quaternion drotate_around_z (double angle)
 Rotation Quaternion for Z axis. More...
 
Quaternion drotate_around (int axis, double angle)
 Rotation Quaternion for indicated axis. More...
 
Quaternion eye (double scale)
 

Function Documentation

Quaternion Cosmos::Math::Quaternions::operator* ( const Vectors::Vector v,
const Quaternion q 
)
2319  {
2320  const Quaternion qv = Quaternion(v);
2321  return qv * q;
2322  }
std::ostream & Cosmos::Math::Quaternions::operator<< ( std::ostream &  os,
const Quaternion q 
)

Scalar division.

Calculate the scalar division with the provided scale.

Parameters
scaleScale to divide by.
Returns
This divided by b.Compound scalar division.
 Calculate the scalar division with the provided scale inline.
Parameters
scaleScale to divide by.
Returns
Reference to this divided by b.
2370  {
2371  //out << "[(";
2372  os << q.x << ",";
2373  os << q.y << ",";
2374  os << q.z << ", ";
2375  os << q.w;
2376  //out << "]"; //<< std::endl;
2377  return os;
2378  }
Quaternion Cosmos::Math::Quaternions::operator* ( double  scale,
const Quaternion q 
)

Reverse scalar product.

Calculate the scalar product with the provided scale.

Parameters
scaleScale to multiply by.
Returns
Scale times this.
2463  {
2464  return q * scale;
2465  }
Quaternion Cosmos::Math::Quaternions::drotate_between ( Vectors::Vector  a,
Vectors::Vector  b 
)

compute the quaternion that represents the rotation from vector a to vector b Ref: - http://lolengine.net/blog/2013/09/18/beautiful-maths-quaternion-from-vectors

2495  {
2496  // normalize the vectors in place
2497  a.normalize();
2498  b.normalize();
2499 
2500  Vectors::Vector vec1;
2501  Vectors::Vector vec2;
2502  Quaternion rq;
2503  if ((a + b).norm() < 1e-14)
2504  {
2505  vec1 = Vector(rand(), rand(), rand());
2506  vec1.normalize();
2507  vec2 = vec1.cross(b);
2508  vec2.normalize();
2509  if (vec2.norm() < D_SMALL)
2510  {
2511  vec1 = Vector(rand(), rand(), rand());
2512  vec1.normalize();
2513  vec2 = vec1.cross(b);
2514  vec2.normalize();
2515  }
2516  rq = Quaternion(vec2);
2517  rq.w = 0.;
2518  }
2519  else
2520  {
2521  rq = Quaternion(a.cross(b));
2522  rq.w = 1. + a.dot(b);
2523  }
2524 
2525  rq.normalize();
2526 
2527  return rq;
2528  }
Definition: eci2kep_test.cpp:33
long b
Definition: jpegint.h:371
Definition: eci2kep_test.cpp:33
const double D_SMALL
Definition: math/constants.h:40
Vector Class.
Definition: vector.h:672
Quaternion Cosmos::Math::Quaternions::irotate_for ( Vectors::Vector  sourcea,
Vectors::Vector  sourceb,
Vectors::Vector  targeta,
Vectors::Vector  targetb 
)

Create irotate quaternion from two orthogonal vectors.

Using two vectors, represented in both the original and target frames, calculate the quaternion that will irotate any vector from the original to the target frame.

Parameters
sourceaFirst vector in source frame
sourcebSecond vector in source frame
targetaFirst vector in target frame
targetbSecond vector in target frame
Returns
Quaternion to use with irotate to irotate from source to target.
2541  {
2542  Quaternion qe_a;
2543  Quaternion qe_b;
2544  Quaternion fqe;
2545 
2546  // Determine rotation of source A into target A
2547  qe_a = (drotate_between(sourcea, targeta)).conjugate();
2548 
2549  // Use to irotate source B into intermediate B
2550  sourceb = qe_a.irotate(sourceb);
2551  sourceb.normalize();
2552  targetb.normalize();
2553  if ((sourceb + targetb).norm() < 1e-14)
2554  {
2555  // Antiparallel - rotate 180 degrees around vector A
2556  qe_b.x = -targeta[0];
2557  qe_b.y = -targeta[1];
2558  qe_b.z = -targeta[2];
2559  qe_b.w = 0;
2560  }
2561  else
2562  {
2563  // Determine intrinsic rotation of this intermediate B into target B
2564  qe_b = (drotate_between(sourceb, targetb)).conjugate();
2565  }
2566 
2567  // Combine to determine complete intrinsic rotation of source into target
2568  fqe = qe_a * qe_b;
2569  fqe.normalize();
2570 
2571  return fqe;
2572  }
Definition: eci2kep_test.cpp:33
Quaternion drotate_between(Vectors::Vector a, Vectors::Vector b)
Definition: vector.cpp:2494
Quaternion Cosmos::Math::Quaternions::drotate_around_x ( double  angle)

Rotation Quaternion for X axis.

Create the ::Quaternion that represents a rotation of the given angle around the X axis.

Parameters
angleAngle of rotation in radians
Returns
Resulting ::Quaternion
2581  {
2582  Quaternion a(0.,1.,0.,0.);
2583 
2584  double sa = sin(angle/2.);
2585 
2586  a.x = sa * a.x;
2587  a.y = sa * a.y;
2588  a.z = sa * a.z;
2589 
2590  a.w = cos(angle/2.);
2591 
2592  return (a);
2593  }
Definition: eci2kep_test.cpp:33
Quaternion Cosmos::Math::Quaternions::drotate_around_y ( double  angle)

Rotation Quaternion for Y axis.

Create the ::Quaternion that represents a rotation of the given angle around the Y axis.

Parameters
angleAngle of rotation in radians
Returns
Resulting ::Quaternion
2601  {
2602  Quaternion a(0.,0.,1.,0.);
2603 
2604  double sa = sin(angle/2.);
2605 
2606  a.x = sa * a.x;
2607  a.y = sa * a.y;
2608  a.z = sa * a.z;
2609 
2610  a.w = cos(angle/2.);
2611 
2612  return (a);
2613  }
Definition: eci2kep_test.cpp:33
Quaternion Cosmos::Math::Quaternions::drotate_around_z ( double  angle)

Rotation Quaternion for Z axis.

Create the ::Quaternion that represents a rotation of the given angle around the Z axis.

Parameters
angleAngle of rotation in radians
Returns
Resulting ::Quaternion
2622  {
2623  Quaternion a(0.,0.,0.,1.);
2624 
2625  double sa = sin(angle/2.);
2626 
2627  a.x = sa * a.x;
2628  a.y = sa * a.y;
2629  a.z = sa * a.z;
2630  a.w = cos(angle/2.);
2631 
2632  return (a);
2633  }
Definition: eci2kep_test.cpp:33
Quaternion Cosmos::Math::Quaternions::drotate_around ( int  axis,
double  angle 
)

Rotation Quaternion for indicated axis.

Create the ::Quaternion that represents a rotation of the given angle around the indicated axis.

Parameters
axisAxis of rotation: 1=X, 2=Y, 3=Z
angleAngle of rotation in radians
Returns
Resulting ::Quaternion
2642  {
2643  Quaternion a(1.,0.,0.,0.);
2644 
2645  switch (axis)
2646  {
2647  case 1:
2648  drotate_around_x(angle);
2649  break;
2650  case 2:
2651  drotate_around_y(angle);
2652  break;
2653  case 3:
2654  drotate_around_z(angle);
2655  break;
2656  }
2657 
2658  return (a);
2659  }
Quaternion drotate_around_x(double angle)
Rotation Quaternion for X axis.
Definition: vector.cpp:2580
Quaternion drotate_around_y(double angle)
Rotation Quaternion for Y axis.
Definition: vector.cpp:2600
Quaternion drotate_around_z(double angle)
Rotation Quaternion for Z axis.
Definition: vector.cpp:2621
Definition: eci2kep_test.cpp:33
Quaternion Cosmos::Math::Quaternions::eye ( double  scale)
2662  {
2663  Quaternion val = Quaternion(0., 0., 0., scale);
2664  return val;
2665  }