COSMOS core  1.0.2 (beta)
Comprehensive Open-architecture Solution for Mission Operations Systems
vector.h File Reference
#include "support/configCosmos.h"
#include "constants.h"
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
Include dependency graph for vector.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  rvector
 3 element generic row vector More...
 
class  cvector
 3 element cartesian vector More...
 
struct  svector
 3 element spherical vector More...
 
struct  gvector
 3 element geodetic vector More...
 
struct  avector
 3 element attitude vector. More...
 
struct  quaternion
 Quaternion, scalar last, using x, y, z. More...
 
struct  qcomplex
 Quaternion, scalar last, using imaginary elements. More...
 
struct  qlast
 Quaternion, scalar last, using vector elements. More...
 
struct  qfirst
 Quaternion, scalar first using vector elements. More...
 
class  Cosmos::Math::Vectors::Vector
 Vector Class. More...
 
class  Cosmos::Math::Vectors::geodeticVector
 
class  Cosmos::Math::Vectors::sphericalVector
 
class  Cosmos::Math::Vectors::eulerVector
 
class  Cosmos::Math::Quaternions::Quaternion
 

Namespaces

 Cosmos
 
 Cosmos::Math
 
 Cosmos::Math::Vectors
 
 Cosmos::Math::Quaternions
 

Functions

std::ostream & operator<< (std::ostream &out, const rvector &a)
 
std::ostream & operator<< (std::ostream &out, const vector< rvector > &a)
 
std::istream & operator>> (std::istream &out, rvector &a)
 
rvector operator* (rvector v, double scalar)
 
rvector operator* (rvector v1, rvector v2)
 
rvector operator/ (rvector v, double scalar)
 
bool operator== (rvector a, rvector b)
 
bool operator!= (rvector a, rvector b)
 
std::ostream & operator<< (std::ostream &out, const svector &a)
 
std::istream & operator>> (std::istream &out, svector &a)
 
std::ostream & operator<< (std::ostream &out, const gvector &a)
 
std::istream & operator>> (std::istream &out, gvector &a)
 
std::ostream & operator<< (std::ostream &out, const avector &a)
 
std::istream & operator>> (std::istream &out, avector &a)
 
std::ostream & operator<< (std::ostream &out, const cvector &a)
 
std::istream & operator>> (std::istream &in, cvector &a)
 
gvector gv_zero ()
 Zero geodetic vector. More...
 
rvector rv_zero ()
 Zero row order vector. More...
 
rvector rv_shortest (rvector v)
 Shortest vector. More...
 
rvector rv_shortest2 (rvector v)
 
rvector rv_unitx (double scale=1.)
 Scaled x row vector. More...
 
rvector rv_unity (double scale=1.)
 Scaled y row vector. More...
 
rvector rv_unitz (double scale=1.)
 Scaled z row vector. More...
 
rvector rv_one ()
 Row vector of ones. More...
 
rvector rv_one (double x, double y, double z)
 Row vector of values. More...
 
rvector rv_smult (double a, rvector b)
 Multiply row vector by scalar. More...
 
rvector rv_normal (rvector v)
 Normalize row order vector. More...
 
rvector rv_normalto (rvector p0, rvector p1, rvector p2)
 Normal to a polygon. More...
 
rvector rv_sadd (double a, rvector b)
 Add scalar to each element of vector. More...
 
rvector rv_add (rvector a, rvector b)
 Add two row vectors. More...
 
rvector rv_sub (rvector a, rvector b)
 Subtract two vectors. More...
 
rvector rv_mult (rvector a, rvector b)
 Multiply two row vectors. More...
 
rvector rv_div (rvector a, rvector b)
 Divide two row vectors. More...
 
rvector rv_sqrt (rvector a)
 Row vector square root. More...
 
rvector rv_cross (rvector a, rvector b)
 Take cross product of two row vectors. More...
 
rvector rv_convert (svector from)
 Convert svector to rvector. More...
 
double norm_rv (rvector a)
 Infinite norm of row vector. More...
 
void normalize_rv (rvector &v)
 Normalize row order vector in place. More...
 
double sep_rv (rvector v1, rvector v2)
 Angular separation between row vectors. More...
 
double dot_rv (rvector a, rvector b)
 Dot product of two row vectors. More...
 
double length_rv (rvector v)
 Length of row vector. More...
 
bool equal_rv (rvector v1, rvector v2)
 Boolean equate of row vetor. More...
 
double sum_rv (rvector a)
 Sum elements of a row vector. More...
 
svector s_convert (rvector from)
 Convert rvector to svector. More...
 
cvector cv_zero ()
 Zero cartesian vector. More...
 
cvector cv_unitx ()
 Unit x vector. More...
 
cvector cv_unity ()
 Unit y vector. More...
 
cvector cv_unitz ()
 Unit z vector. More...
 
cvector cv_one ()
 Vector of ones. More...
 
cvector cv_normal (cvector v)
 Normalize cartesian vector. More...
 
cvector cv_cross (cvector a, cvector b)
 Take cross product of two vectors. More...
 
cvector cv_sadd (double a, cvector b)
 Add scalar to each element of vector. More...
 
cvector cv_add (cvector a, cvector b)
 Add two vectors. More...
 
cvector cv_sub (cvector a, cvector b)
 Subtract two vectors. More...
 
cvector cv_mult (cvector a, cvector b)
 Multiply two vectors. More...
 
cvector cv_div (cvector a, cvector b)
 Divide two vectors. More...
 
cvector cv_smult (double a, cvector b)
 Multiply vector by scalar. More...
 
cvector cv_sqrt (cvector a)
 
void normalize_cv (cvector &v)
 Normalize cartesian vector in place, i.e. divides it by its own norm. More...
 
double sep_cv (cvector v1, cvector v2)
 Angular separation between vectors. More...
 
double dot_cv (cvector a, cvector b)
 
double length_cv (cvector v)
 
double norm_cv (cvector v)
 
double cv_norm (cvector v)
 
double sum_cv (cvector a)
 
std::ostream & operator<< (std::ostream &out, const quaternion &a)
 
std::istream & operator>> (std::istream &out, quaternion &a)
 
std::ostream & operator<< (std::ostream &out, const qcomplex &a)
 
std::istream & operator>> (std::istream &out, qcomplex &a)
 
std::ostream & operator<< (std::ostream &out, const qlast &a)
 
std::istream & operator>> (std::istream &out, qlast &a)
 
std::ostream & operator<< (std::ostream &out, const qfirst &a)
 
std::istream & operator>> (std::istream &out, qfirst &a)
 
cvector cv_quaternion2axis (quaternion q)
 
void normalize_q (quaternion *q)
 
quaternion q_zero ()
 Zero quaternion. More...
 
quaternion q_conjugate (quaternion q)
 
quaternion q_times (quaternion q1, quaternion q2)
 Multiply the elements of 2 quaternions. More...
 
quaternion q_sqrt (quaternion q1)
 Square root of the elements of a quaternion. More...
 
quaternion q_fmult (rvector r1, quaternion q2)
 rvector quaternion multiply More...
 
quaternion q_fmult (quaternion q1, quaternion q2)
 
quaternion q_mult (quaternion q1, quaternion q2)
 
quaternion q_rmult (quaternion q1, quaternion q2)
 
quaternion q_smult (double a, quaternion q)
 Multiply quaternion by scalar. More...
 
quaternion q_add (quaternion q1, quaternion q2)
 Add two quaternions. More...
 
quaternion q_sub (quaternion q1, quaternion q2)
 Subtract two quaternions. More...
 
quaternion q_euler2quaternion (avector rpw)
 
quaternion q_axis2quaternion_cv (cvector v)
 
quaternion q_axis2quaternion_rv (rvector v)
 Row vector axis and angle to Quaternion. More...
 
quaternion q_drotate_between_rv (rvector from, rvector to)
 Create rotation quaternion from 2 row vectors. More...
 
quaternion q_change_around_cv (cvector around, double angle)
 Create rotation quaternion from axis and angle. More...
 
quaternion q_change_around_rv (rvector around, double angle)
 Create rotation quaternion from row vector axis and angle. More...
 
quaternion q_change_around_x (double angle)
 Rotation quaternion for X axis. More...
 
quaternion q_change_around_y (double angle)
 Rotation quaternion for Y axis. More...
 
quaternion q_change_around_z (double angle)
 Rotation quaternion for Z axis. More...
 
quaternion q_irotate_for (rvector sourcea, rvector sourceb, rvector targeta, rvector targetb)
 Create irotate quaternion from two orthogonal vectors. More...
 
quaternion q_eye ()
 Identity quaternion. More...
 
quaternion q_identity ()
 
quaternion q_evaluate_poly (double x, vector< vector< double > > parms)
 Evaluate quaternion polynomial. More...
 
quaternion q_evaluate_poly_slope (double x, vector< vector< double > > parms)
 Evaluate quaternion polynomial slope. More...
 
quaternion q_evaluate_poly_accel (double x, vector< vector< double > > parms)
 Evaluate quaternion polynomial acceleration. More...
 
quaternion q_evaluate_poly_jerk (double x, vector< vector< double > > parms)
 Evaluate quaternion polynomial jerk. More...
 
double length_q (quaternion q)
 Length of quaternion. More...
 
double norm_q (quaternion q)
 
double sep_q (quaternion q1, quaternion q2)
 Angular separation between quaternions. More...
 
double inner_q (quaternion q1, quaternion q2)
 Inner product of two quaternions. More...
 
void qrotate (double ipos[3], double rpos[3], double angle, double *opos)
 
avector a_quaternion2euler (quaternion q)
 
quaternion q_change_between_cv (cvector from, cvector to)
 Create rotation quaternion from 2 vectors. More...
 
quaternion q_change_between_rv (rvector from, rvector to)
 
Vector Cosmos::Math::Vectors::operator* (const double scale, const Vector &v)
 Reverse scalar product. More...
 
std::ostream & Cosmos::Math::Vectors::operator<< (std::ostream &out, const Vector &v)
 
Vector Cosmos::Math::Vectors::eye (double scale)
 
Vector Cosmos::Math::Vectors::unitxV (double scale)
 
Vector Cosmos::Math::Vectors::unityV (double scale)
 
Vector Cosmos::Math::Vectors::unitzV (double scale)
 
Quaternion Cosmos::Math::Quaternions::operator* (double scale, const Quaternion &q)
 Reverse scalar product. More...
 
Quaternion Cosmos::Math::Quaternions::operator* (const Vectors::Vector &v, const Quaternion &q)
 
std::ostream & Cosmos::Math::Quaternions::operator<< (std::ostream &os, const Quaternion &q)
 Scalar division. More...
 
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. More...
 
Quaternion Cosmos::Math::Quaternions::drotate_between (Vectors::Vector a, Vectors::Vector b)
 
Quaternion Cosmos::Math::Quaternions::drotate_around_x (double angle)
 Rotation Quaternion for X axis. More...
 
Quaternion Cosmos::Math::Quaternions::drotate_around_y (double angle)
 Rotation Quaternion for Y axis. More...
 
Quaternion Cosmos::Math::Quaternions::drotate_around_z (double angle)
 Rotation Quaternion for Z axis. More...
 
Quaternion Cosmos::Math::Quaternions::drotate_around (int axis, double angle)
 Rotation Quaternion for indicated axis. More...
 
Quaternion Cosmos::Math::Quaternions::eye (double scale)
 

Function Documentation

std::ostream& operator<< ( std::ostream &  out,
const rvector a 
)
801 {
802 
803  // // fancy formating
804  // //out.precision(15);
805  // out << std::fixed;
806  // out << std::setprecision(6);
807  // out<< "["
808  // << std::setw(10) << a.col[0] << ","
809  // << std::setw(10) << a.col[1] << ","
810  // << std::setw(10) << a.col[2];
811  // << "]";
812 
813  // // remove formating for floatfield (not set)
814  // std::cout.unsetf ( std::ios::floatfield );
815 
816  // simple formating
817  out << a.col[0] << ","
818  << a.col[1] << ","
819  << a.col[2];
820 
821  return out;
822 }
double col[3]
Definition: vector.h:55
std::ostream& operator<< ( std::ostream &  out,
const vector< rvector > &  a 
)
825 {
826  for(vector<rvector>::const_iterator I = a.begin(); I != a.end(); ++I)
827  out<<*I<<"\t";
828  return out;
829 }
Definition: eci2kep_test.cpp:33
std::istream& operator>> ( std::istream &  out,
rvector a 
)
832 {
833  char junk;
834  in >> junk >> a.col[0] >> junk >> a.col[1] >> junk >> a.col[2] >> junk;
835  return in;
836 }
double col[3]
Definition: vector.h:55
rvector operator* ( rvector  v,
double  scalar 
)
840 {
841  return rv_smult(scalar, v);
842 }
rvector rv_smult(double a, rvector b)
Multiply row vector by scalar.
Definition: vector.cpp:266
rvector operator* ( rvector  v1,
rvector  v2 
)
852 {
853  return rv_mult(v1, v2);
854 }
rvector rv_mult(rvector a, rvector b)
Multiply two row vectors.
Definition: vector.cpp:347
rvector operator/ ( rvector  v,
double  scalar 
)
858 {
859  return rv_smult(1./scalar, v);
860 }
rvector rv_smult(double a, rvector b)
Multiply row vector by scalar.
Definition: vector.cpp:266
bool operator== ( rvector  a,
rvector  b 
)
864 {
865  if(a.col[0] == b.col[0] && a.col[1] == b.col[1] && a.col[2] == b.col[2])
866  {
867  return true;
868  }
869  else
870  {
871  return false;
872  }
873 }
double col[3]
Definition: vector.h:55
bool operator!= ( rvector  a,
rvector  b 
)
877 {
878  if(a.col[0] != b.col[0] || a.col[1] != b.col[1] || a.col[2] != b.col[2])
879  {
880  return true;
881  }
882  else
883  {
884  return false;
885  }
886 }
double col[3]
Definition: vector.h:55
std::ostream& operator<< ( std::ostream &  out,
const svector a 
)
902 {
903  out << "[" << a.phi << "," << a.lambda << "," << a.r << "]";
904  return out;
905 }
double lambda
E/W in radians.
Definition: vector.h:172
double phi
N/S in radians.
Definition: vector.h:170
double r
Radius in meters.
Definition: vector.h:174
std::istream& operator>> ( std::istream &  out,
svector a 
)
908 {
909  char junk;
910  in >> junk >> a.phi >> junk >> a.lambda >> junk >> a.r >> junk;
911  return in;
912 }
double lambda
E/W in radians.
Definition: vector.h:172
double phi
N/S in radians.
Definition: vector.h:170
double r
Radius in meters.
Definition: vector.h:174
std::ostream& operator<< ( std::ostream &  out,
const gvector a 
)
915 {
916  out<<"["<<a.lat<<","<<a.lon<<","<<a.h<<"]";
917  return out;
918 }
double h
Height in meters.
Definition: vector.h:229
double lon
Longitude in radians.
Definition: vector.h:227
double lat
Latitude in radians.
Definition: vector.h:225
std::istream& operator>> ( std::istream &  out,
gvector a 
)
921 {
922  char junk;
923  in >> junk >> a.lat >> junk >> a.lon >> junk >> a.h >> junk;
924  return in;
925 }
double h
Height in meters.
Definition: vector.h:229
double lon
Longitude in radians.
Definition: vector.h:227
double lat
Latitude in radians.
Definition: vector.h:225
std::ostream& operator<< ( std::ostream &  out,
const avector a 
)
928 {
929  out << "[" << a.h << "," << a.e << "," << a.b << "]";
930  return out;
931 }
double e
Elevation.
Definition: vector.h:282
double b
Bank.
Definition: vector.h:284
double h
Heading.
Definition: vector.h:280
std::istream& operator>> ( std::istream &  out,
avector a 
)
934 {
935  char junk;
936  in >> junk >> a.h >> junk >> a.e >> junk >> a.b >> junk;
937  return in;
938 }
double e
Elevation.
Definition: vector.h:282
double b
Bank.
Definition: vector.h:284
double h
Heading.
Definition: vector.h:280
std::ostream& operator<< ( std::ostream &  out,
const cvector a 
)
889 {
890  out << "[" << a.x << "," << a.y << "," << a.z << "]";
891  return out;
892 }
double y
Y value.
Definition: vector.h:114
double x
X value.
Definition: vector.h:112
double z
Z value.
Definition: vector.h:116
std::istream& operator>> ( std::istream &  in,
cvector a 
)
895 {
896  char junk;
897  in >> junk >> a.x >> junk >> a.y >> junk >> a.z >> junk;
898  return in;
899 }
double y
Y value.
Definition: vector.h:114
double x
X value.
Definition: vector.h:112
double z
Z value.
Definition: vector.h:116
gvector gv_zero ( )

Zero geodetic vector.

Creates a zero length geodetic vector.

Returns
a gvector of zero length
947 {
948  gvector v={0.,0.,0.};
949 
950  return (v);
951 }
3 element geodetic vector
Definition: vector.h:222
std::ostream& operator<< ( std::ostream &  out,
const quaternion a 
)
1508 {
1509  //out << std::fixed;
1510  //out << std::setprecision(5);
1511  //out<< "[("
1512  //out << std::setw(6);
1513  out << a.d.x << ",";
1514  //out << std::setw(6);
1515  out << a.d.y << ",";
1516  //out << std::setw(6);
1517  out << a.d.z << ", ";
1518  //out << std::setw(6)
1519  out << a.w;
1520  // << "]";
1521 
1522  // remove formating for floatfield (not set)
1523  // std::cout.unsetf ( std::ios::floatfield );
1524 
1525  return out;
1526 }
double y
Y value.
Definition: vector.h:114
cvector d
Orientation.
Definition: vector.h:405
double x
X value.
Definition: vector.h:112
double w
Rotation.
Definition: vector.h:407
double z
Z value.
Definition: vector.h:116
std::istream& operator>> ( std::istream &  out,
quaternion a 
)
1529 {
1530  char junk;
1531  in >> junk >> a.d.x >> junk >> a.d.y >> junk >> a.d.z >> junk >> a.w >> junk;
1532  return in;
1533 }
double y
Y value.
Definition: vector.h:114
cvector d
Orientation.
Definition: vector.h:405
double x
X value.
Definition: vector.h:112
double w
Rotation.
Definition: vector.h:407
double z
Z value.
Definition: vector.h:116
std::ostream& operator<< ( std::ostream &  out,
const qcomplex a 
)
1536 {
1537  out<< "[" << a.i << "," << a.j << "," << a.k << "," << a.r << "]";
1538  return out;
1539 }
double j
Definition: vector.h:453
double i
Definition: vector.h:452
double r
Definition: vector.h:455
double k
Definition: vector.h:454
std::istream& operator>> ( std::istream &  out,
qcomplex a 
)
1542 {
1543  char junk;
1544  in >> junk >> a.i >> junk >> a.j >> junk >> a.k >> junk >> a.r >> junk;
1545  return in;
1546 }
double j
Definition: vector.h:453
double i
Definition: vector.h:452
double r
Definition: vector.h:455
double k
Definition: vector.h:454
std::ostream& operator<< ( std::ostream &  out,
const qlast a 
)
1549 {
1550  out << "[" << a.q1 << "," << a.q2 << "," << a.q3 << "," << a.q4 << "]";
1551  return out;
1552 }
double q2
Definition: vector.h:509
double q4
Definition: vector.h:511
double q3
Definition: vector.h:510
double q1
Definition: vector.h:508
std::istream& operator>> ( std::istream &  out,
qlast a 
)
1555 {
1556  char junk;
1557  in >> junk >> a.q1 >> junk >> a.q2 >> junk >> a.q3 >> junk >> a.q4 >> junk;
1558  return in;
1559 }
double q2
Definition: vector.h:509
double q4
Definition: vector.h:511
double q3
Definition: vector.h:510
double q1
Definition: vector.h:508
std::ostream& operator<< ( std::ostream &  out,
const qfirst a 
)
1562 {
1563  out << "[" << a.q0 << "," << a.q1 << "," << a.q2 << "," << a.q3 << "]";
1564  return out;
1565 }
double q1
Definition: vector.h:565
double q0
Definition: vector.h:564
double q3
Definition: vector.h:567
double q2
Definition: vector.h:566
std::istream& operator>> ( std::istream &  out,
qfirst a 
)
1568 {
1569  char junk;
1570  in >> junk >> a.q0 >> junk >> a.q1 >> junk >> a.q2 >> junk >> a.q3 >> junk;
1571  return in;
1572 }
double q1
Definition: vector.h:565
double q0
Definition: vector.h:564
double q3
Definition: vector.h:567
double q2
Definition: vector.h:566
cvector cv_quaternion2axis ( quaternion  q)
1343 {
1344  cvector v;
1345  double ca, sa;
1346 
1347  ca = 2.*acos(q.w);
1348  if (ca > 0.)
1349  {
1350  sa = sin(ca/2.);
1351  v.x = ca*(q.d.x/sa);
1352  v.y = ca*(q.d.y/sa);
1353  v.z = ca*(q.d.z/sa);
1354  }
1355  else
1356  v = {0.,0.,0.};
1357 
1358  return (v);
1359 }
double y
Y value.
Definition: vector.h:114
cvector d
Orientation.
Definition: vector.h:405
double x
X value.
Definition: vector.h:112
double w
Rotation.
Definition: vector.h:407
double z
Z value.
Definition: vector.h:116
3 element cartesian vector
Definition: vector.h:107
void normalize_q ( quaternion q)
962 {
963  double mag;
964 
965  q->w = round(q->w/D_SMALL)*D_SMALL;
966  q->d.x = round(q->d.x/D_SMALL)*D_SMALL;
967  q->d.y = round(q->d.y/D_SMALL)*D_SMALL;
968  q->d.z = round(q->d.z/D_SMALL)*D_SMALL;
969 
970  mag = q->w * q->w + q->d.x * q->d.x + q->d.y * q->d.y + q->d.z * q->d.z;
971 
972  if (fabs(mag - (double)0.) > D_SMALL && fabs(mag - (double)1.) > D_SMALL)
973  {
974  mag = sqrt(mag);
975  q->w /= mag;
976  q->d.x /= mag;
977  q->d.y /= mag;
978  q->d.z /= mag;
979  }
980 }
double y
Y value.
Definition: vector.h:114
cvector d
Orientation.
Definition: vector.h:405
double x
X value.
Definition: vector.h:112
double w
Rotation.
Definition: vector.h:407
const double D_SMALL
Definition: math/constants.h:40
double z
Z value.
Definition: vector.h:116
quaternion q_zero ( )

Zero quaternion.

Creates a quaternion filled with zeros.

Returns
a quaternion of zeros
1004 {
1005  quaternion q={{0.,0.,0.},0.};
1006 
1007  return (q);
1008 }
Quaternion, scalar last, using x, y, z.
Definition: vector.h:402
quaternion q_conjugate ( quaternion  q)
1011 {
1012  quaternion o;
1013 
1014  o.w = q.w;
1015  o.d.x = -q.d.x;
1016  o.d.y = -q.d.y;
1017  o.d.z = -q.d.z;
1018 
1019  return (o);
1020 }
double y
Y value.
Definition: vector.h:114
cvector d
Orientation.
Definition: vector.h:405
Quaternion, scalar last, using x, y, z.
Definition: vector.h:402
double x
X value.
Definition: vector.h:112
double w
Rotation.
Definition: vector.h:407
double z
Z value.
Definition: vector.h:116
quaternion q_times ( quaternion  q1,
quaternion  q2 
)

Multiply the elements of 2 quaternions.

Multiply each element of one quaternion by the same element of the other.

Parameters
q1First quaternion
q2second quaternion
Returns
Quaternion result
1029 {
1030  quaternion o;
1031 
1032  o.d.x = q1.d.x * q2.d.x;
1033  o.d.y = q1.d.y * q2.d.y;
1034  o.d.z = q1.d.z * q2.d.z;
1035  o.w = q1.w * q2.w;
1036 
1037  return (o);
1038 }
double y
Y value.
Definition: vector.h:114
cvector d
Orientation.
Definition: vector.h:405
Quaternion, scalar last, using x, y, z.
Definition: vector.h:402
double x
X value.
Definition: vector.h:112
double w
Rotation.
Definition: vector.h:407
double z
Z value.
Definition: vector.h:116
quaternion q_sqrt ( quaternion  q1)

Square root of the elements of a quaternion.

Take the square root of each element of one quaternion.

Parameters
q1quaternion
Returns
Quaternion result
1061 {
1062  quaternion o;
1063 
1064  o.d.x = sqrt(q1.d.x);
1065  o.d.y = sqrt(q1.d.y);
1066  o.d.z = sqrt(q1.d.z);
1067  o.w = sqrt(q1.w);
1068 
1069  return (o);
1070 }
double y
Y value.
Definition: vector.h:114
cvector d
Orientation.
Definition: vector.h:405
Quaternion, scalar last, using x, y, z.
Definition: vector.h:402
double x
X value.
Definition: vector.h:112
double w
Rotation.
Definition: vector.h:407
double z
Z value.
Definition: vector.h:116
quaternion q_fmult ( rvector  r1,
quaternion  q2 
)

rvector quaternion multiply

Treat an rvector as a quaternion with scalar set to zero, then quaternion multiply the rvector by the quaternion.

Parameters
r1rvector as first quaternion.
q2second quaternion
Returns
Quaternion result
1080 {
1081  quaternion o;
1082 
1083  o.d.x = r1.col[0] * q2.w + r1.col[1] * q2.d.z - r1.col[2] * q2.d.y;
1084  o.d.y = r1.col[1] * q2.w + r1.col[2] * q2.d.x - r1.col[0] * q2.d.z;
1085  o.d.z = r1.col[2] * q2.w + r1.col[0] * q2.d.y - r1.col[1] * q2.d.x;
1086  o.w = - r1.col[0] * q2.d.x - r1.col[1] * q2.d.y - r1.col[2] * q2.d.z;
1087 
1088  return (o);
1089 }
double y
Y value.
Definition: vector.h:114
cvector d
Orientation.
Definition: vector.h:405
Quaternion, scalar last, using x, y, z.
Definition: vector.h:402
double x
X value.
Definition: vector.h:112
double w
Rotation.
Definition: vector.h:407
double z
Z value.
Definition: vector.h:116
double col[3]
Definition: vector.h:55
quaternion q_fmult ( quaternion  q1,
quaternion  q2 
)

Quaternion multiplication. The result of multiplying two quaternions is the composition of two rotations (not commutative). This function creates a result that would behave like rotating first by q1, then by q2.

Quaternion multiply two quaternions.

Parameters
q1First quaternion
q2Second quaternion
Returns
Quaternion result.
1100 {
1101  quaternion o;
1102 
1103  o.d.x = q1.w * q2.d.x + q1.d.x * q2.w + q1.d.y * q2.d.z - q1.d.z * q2.d.y;
1104  o.d.y = q1.w * q2.d.y + q1.d.y * q2.w + q1.d.z * q2.d.x - q1.d.x * q2.d.z;
1105  o.d.z = q1.w * q2.d.z + q1.d.z * q2.w + q1.d.x * q2.d.y - q1.d.y * q2.d.x;
1106  o.w = q1.w * q2.w - q1.d.x * q2.d.x - q1.d.y * q2.d.y - q1.d.z * q2.d.z;
1107 
1108  return (o);
1109 }
double y
Y value.
Definition: vector.h:114
cvector d
Orientation.
Definition: vector.h:405
Quaternion, scalar last, using x, y, z.
Definition: vector.h:402
double x
X value.
Definition: vector.h:112
double w
Rotation.
Definition: vector.h:407
double z
Z value.
Definition: vector.h:116
quaternion q_mult ( quaternion  q1,
quaternion  q2 
)

Quaternion multiplication. The result of multiplying two quaternions is the composition of two rotations (not commutative). This function creates a result that would behave like rotating first by q1, then by q2.

Quaternion multiply two quaternions.

Parameters
q1First quaternion
q2Second quaternion
Returns
Quaternion result.
1120 {
1121  return q_fmult(q1, q2);
1122 }
quaternion q_fmult(rvector r1, quaternion q2)
rvector quaternion multiply
Definition: vector.cpp:1079
quaternion q_rmult ( quaternion  q1,
quaternion  q2 
)

Quaternion multiplication. The result of multiplying two quaternions is the composition of two rotations (not commutative). This function creates a result that would behave like rotating first by q2, then by q1. It is the conjugate of q_fmult().

Quaternion multiply two quaternions.

Parameters
q1First quaternion
q2Second quaternion
Returns
Quaternion result.
1134 {
1135  quaternion o;
1136 
1137  o.d.x = q1.w * q2.d.x + q1.d.x * q2.w + q1.d.y * q2.d.z - q1.d.z * q2.d.y;
1138  o.d.y = q1.w * q2.d.y + q1.d.y * q2.w + q1.d.z * q2.d.x - q1.d.x * q2.d.z;
1139  o.d.z = q1.w * q2.d.z + q1.d.z * q2.w + q1.d.x * q2.d.y - q1.d.y * q2.d.x;
1140  o.w = -q1.w * q2.w + q1.d.x * q2.d.x + q1.d.y * q2.d.y + q1.d.z * q2.d.z;
1141 
1142  return (o);
1143 }
double y
Y value.
Definition: vector.h:114
cvector d
Orientation.
Definition: vector.h:405
Quaternion, scalar last, using x, y, z.
Definition: vector.h:402
double x
X value.
Definition: vector.h:112
double w
Rotation.
Definition: vector.h:407
double z
Z value.
Definition: vector.h:116
quaternion q_smult ( double  a,
quaternion  b 
)

Multiply quaternion by scalar.

Multiply a 3 element quaternion by a double precision scalar.

Parameters
bquaternion to be tranformed, in quaternion form
adouble precision scalar to multiply by
Returns
the transformed quaternion, in quaternion form
1152 {
1153  quaternion c;
1154 
1155  c.w = a * b.w;
1156  c.d.x = a * b.d.x;
1157  c.d.y = a * b.d.y;
1158  c.d.z = a * b.d.z;
1159  return (c);
1160 }
double y
Y value.
Definition: vector.h:114
cvector d
Orientation.
Definition: vector.h:405
Quaternion, scalar last, using x, y, z.
Definition: vector.h:402
double x
X value.
Definition: vector.h:112
double w
Rotation.
Definition: vector.h:407
Definition: eci2kep_test.cpp:33
double z
Z value.
Definition: vector.h:116
quaternion q_add ( quaternion  a,
quaternion  b 
)

Add two quaternions.

Add two quaternions in quaternion form, returning a quaternion.

Parameters
afirst quaternion to be added, in quaternion form
bsecond quaternion to be added, in quaternion form
Returns
the transformed quaternion, in quaternion form
1169 {
1170  quaternion c;
1171 
1172  c.w = a.w + b.w;
1173  c.d.x = a.d.x + b.d.x;
1174  c.d.y = a.d.y + b.d.y;
1175  c.d.z = a.d.z + b.d.z;
1176  return (c);
1177 }
double y
Y value.
Definition: vector.h:114
cvector d
Orientation.
Definition: vector.h:405
Quaternion, scalar last, using x, y, z.
Definition: vector.h:402
double x
X value.
Definition: vector.h:112
double w
Rotation.
Definition: vector.h:407
double z
Z value.
Definition: vector.h:116
quaternion q_sub ( quaternion  a,
quaternion  b 
)

Subtract two quaternions.

Subtract two quaternions in quaternion form, returning a quaternion.

Parameters
aquaternion to be subtracted from, in quaternion form
bquaternion to be subtracted, in quaternion form
Returns
the transformed quaternion, in quaternion form
1187 {
1188  quaternion c;
1189 
1190  c.w = a.w - b.w;
1191  c.d.x = a.d.x - b.d.x;
1192  c.d.y = a.d.y - b.d.y;
1193  c.d.z = a.d.z - b.d.z;
1194  return (c);
1195 }
double y
Y value.
Definition: vector.h:114
cvector d
Orientation.
Definition: vector.h:405
Quaternion, scalar last, using x, y, z.
Definition: vector.h:402
double x
X value.
Definition: vector.h:112
double w
Rotation.
Definition: vector.h:407
double z
Z value.
Definition: vector.h:116
quaternion q_euler2quaternion ( avector  rpw)
1234 {
1235  quaternion q;
1236  double sr, sp, sy, cr, cp, cy;
1237 
1238  sr = sin(rpw.b/2.);
1239  sp = sin(rpw.e/2.);
1240  sy = sin(rpw.h/2.);
1241  cr = cos(rpw.b/2.);
1242  cp = cos(rpw.e/2.);
1243  cy = cos(rpw.h/2.);
1244 
1245  q.d.x = sr * cp * cy - cr * sp * sy;
1246  q.d.y = cr * sp * cy + sr * cp * sy;
1247  q.d.z = cr * cp * sy - sr * sp * cy;
1248  q.w = (cr * cp * cy + sr * sp * sy);
1249 
1250  normalize_q(&q);
1251 
1252  return (q);
1253 }
double y
Y value.
Definition: vector.h:114
cvector d
Orientation.
Definition: vector.h:405
Quaternion, scalar last, using x, y, z.
Definition: vector.h:402
double x
X value.
Definition: vector.h:112
double e
Elevation.
Definition: vector.h:282
void normalize_q(quaternion *q)
Definition: vector.cpp:961
double b
Bank.
Definition: vector.h:284
double w
Rotation.
Definition: vector.h:407
double z
Z value.
Definition: vector.h:116
double h
Heading.
Definition: vector.h:280
quaternion q_axis2quaternion_cv ( cvector  v)
1283 {
1284  double length, s2;
1285  quaternion q;
1286 
1287  length = sqrt(v.x*v.x+v.y*v.y+v.z*v.z);
1288  s2 = sin(length/2.)/length;
1289  if (length)
1290  {
1291  q.d.x = s2*v.x;
1292  q.d.y = s2*v.y;
1293  q.d.z = s2*v.z;
1294  }
1295  else
1296  q.d.x = q.d.y = q.d.z = 0.;
1297  q.w =cos(length/2);
1298 
1299  normalize_q(&q);
1300  return (q);
1301 }
double y
Y value.
Definition: vector.h:114
cvector d
Orientation.
Definition: vector.h:405
Quaternion, scalar last, using x, y, z.
Definition: vector.h:402
double x
X value.
Definition: vector.h:112
void normalize_q(quaternion *q)
Definition: vector.cpp:961
double w
Rotation.
Definition: vector.h:407
double z
Z value.
Definition: vector.h:116
png_uint_32 length
Definition: png.c:2173
quaternion q_change_around_cv ( cvector  around,
double  angle 
)

Create rotation quaternion from axis and angle.

Generate the quaternion that represents a rotation of the specified angle around the specified axis.

Parameters
aroundcartesian vector around which the rotation will occur
angleamount of rotation in radians
Returns
quaternion that can be used to rotate points
1373 {
1374  double sa;
1375  quaternion rq;
1376 
1377  angle /= 2.;
1378  sa = sin(angle);
1379 
1380  // normalize vector
1381  // before it was normalize_cv(around);
1382 
1383  double mag = around.x*around.x
1384  + around.y*around.y
1385  + around.z*around.z;
1386 
1387  if (fabs(mag - (double)0.) > D_SMALL && fabs(mag - (double)1.) > D_SMALL)
1388  {
1389  mag = sqrt(mag);
1390  around.x /= mag;
1391  around.y /= mag;
1392  around.z /= mag;
1393  }
1394 
1395  rq.d.x = around.x * sa;
1396  rq.d.y = around.y * sa;
1397  rq.d.z = around.z * sa;
1398  rq.w = cos(angle);
1399  normalize_q(&rq);
1400  return (rq);
1401 }
double y
Y value.
Definition: vector.h:114
cvector d
Orientation.
Definition: vector.h:405
Quaternion, scalar last, using x, y, z.
Definition: vector.h:402
double x
X value.
Definition: vector.h:112
void normalize_q(quaternion *q)
Definition: vector.cpp:961
double w
Rotation.
Definition: vector.h:407
const double D_SMALL
Definition: math/constants.h:40
double z
Z value.
Definition: vector.h:116
quaternion q_change_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
1411 {
1412  quaternion a = {{1.,0.,0.},0.};
1413 
1414  // removed cv_mult to clean the dependency from mathlib
1415  // previously was: a.d = cv_smult(sin(angle/2.),a.d);
1416 
1417  // new
1418  double sa = sin(angle/2.);
1419 
1420  a.d.x = sa * a.d.x;
1421  a.d.y = sa * a.d.y;
1422  a.d.z = sa * a.d.z;
1423 
1424  a.w = cos(angle/2.);
1425 
1426  return (a);
1427 }
double y
Y value.
Definition: vector.h:114
cvector d
Orientation.
Definition: vector.h:405
Quaternion, scalar last, using x, y, z.
Definition: vector.h:402
double x
X value.
Definition: vector.h:112
double w
Rotation.
Definition: vector.h:407
Definition: eci2kep_test.cpp:33
double z
Z value.
Definition: vector.h:116
quaternion q_change_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
1436 {
1437  quaternion a = {{0.,1.,0.},0.};
1438 
1439  // removed cv_mult to clean the dependency from mathlib
1440  // previously was: a.d = cv_smult(sin(angle/2.),a.d);
1441 
1442  // new
1443  double sa = sin(angle/2.);
1444 
1445  a.d.x = sa * a.d.x;
1446  a.d.y = sa * a.d.y;
1447  a.d.z = sa * a.d.z;
1448 
1449  a.w = cos(angle/2.);
1450 
1451  return (a);
1452 }
double y
Y value.
Definition: vector.h:114
cvector d
Orientation.
Definition: vector.h:405
Quaternion, scalar last, using x, y, z.
Definition: vector.h:402
double x
X value.
Definition: vector.h:112
double w
Rotation.
Definition: vector.h:407
Definition: eci2kep_test.cpp:33
double z
Z value.
Definition: vector.h:116
quaternion q_change_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
1462 {
1463  quaternion a = {{0.,0.,1.},0.};
1464 
1465  // removed cv_mult to clean the dependency from mathlib
1466  // previously was: a.d = cv_smult(sin(angle/2.),a.d);
1467 
1468  // new
1469  double sa = sin(angle/2.);
1470 
1471  a.d.x = sa * a.d.x;
1472  a.d.y = sa * a.d.y;
1473  a.d.z = sa * a.d.z;
1474  a.w = cos(angle/2.);
1475 
1476  return (a);
1477 }
double y
Y value.
Definition: vector.h:114
cvector d
Orientation.
Definition: vector.h:405
Quaternion, scalar last, using x, y, z.
Definition: vector.h:402
double x
X value.
Definition: vector.h:112
double w
Rotation.
Definition: vector.h:407
Definition: eci2kep_test.cpp:33
double z
Z value.
Definition: vector.h:116
quaternion q_eye ( )

Identity quaternion.

Returns a quaternion that will cause no rotation when multiplied by a vector.

Returns
Identity quaternion
1311 {
1312  quaternion q = {{0.,0.,0.},1.};
1313 
1314  return (q);
1315 }
Quaternion, scalar last, using x, y, z.
Definition: vector.h:402
quaternion q_identity ( )
1318 {
1319  return q_eye();
1320 }
quaternion q_eye()
Identity quaternion.
Definition: vector.cpp:1310
double length_q ( quaternion  q)

Length of quaternion.

Calculate the length of a quaternion by summing the squares of its elements.

Parameters
qQuaternion to find the length of.
Returns
Length of quaternion.
1330 {
1331  double length;
1332 
1333  length = q.w * q.w + q.d.x * q.d.x + q.d.y * q.d.y + q.d.z * q.d.z;
1334  length = sqrt(length);
1335 
1336  if (length < D_SMALL)
1337  return (0.);
1338  else
1339  return (length);
1340 }
double y
Y value.
Definition: vector.h:114
cvector d
Orientation.
Definition: vector.h:405
double x
X value.
Definition: vector.h:112
double w
Rotation.
Definition: vector.h:407
const double D_SMALL
Definition: math/constants.h:40
double z
Z value.
Definition: vector.h:116
png_uint_32 length
Definition: png.c:2173
double norm_q ( quaternion  q)
957 {
958  return length_q(q);
959 }
double length_q(quaternion q)
Length of quaternion.
Definition: vector.cpp:1329
double sep_q ( quaternion  q1,
quaternion  q2 
)

Angular separation between quaternions.

Calculates the separation angle between two quaternions, in radians.

Parameters
q1the first quaternion
q2the second quaternion
Returns
The separation angle in radians as a double precision
989 {
990 
991  normalize_q(&q1);
992  normalize_q(&q2);
993 
994  double inner = inner_q(q1, q2);
995  double sepangle = acos(2. * inner * inner - 1);
996  return (sepangle);
997 }
void normalize_q(quaternion *q)
Definition: vector.cpp:961
double inner_q(quaternion q1, quaternion q2)
Inner product of two quaternions.
Definition: vector.cpp:1047
double inner_q ( quaternion  q1,
quaternion  q2 
)

Inner product of two quaternions.

Multiply each element of one quaternion by the same element of the other, and sum.

Parameters
q1First quaternion
q2second quaternion
Returns
Double result
1048 {
1049  quaternion q = q_times(q1, q2);
1050  double result = q.d.x + q.d.y + q.d.z + q.w;
1051 
1052  return result;
1053 }
double y
Y value.
Definition: vector.h:114
cvector d
Orientation.
Definition: vector.h:405
Quaternion, scalar last, using x, y, z.
Definition: vector.h:402
double x
X value.
Definition: vector.h:112
double w
Rotation.
Definition: vector.h:407
double z
Z value.
Definition: vector.h:116
quaternion q_times(quaternion q1, quaternion q2)
Multiply the elements of 2 quaternions.
Definition: vector.cpp:1028
void qrotate ( double  ipos[3],
double  rpos[3],
double  angle,
double *  opos 
)
1200 {
1201  double q1, q2, q3, q4, length, sa;
1202  double q11, q12, q13, q14, q22, q23, q24, q33, q34;
1203 
1204  length = sqrt(rpos[0]*rpos[0]+rpos[1]*rpos[1]+rpos[2]*rpos[2]);
1205  if (length>0.)
1206  {
1207  rpos[0] /= length;
1208  rpos[1] /= length;
1209  rpos[2] /= length;
1210  }
1211 
1212  sa = sin(angle/2.);
1213  q1 = rpos[0] * sa;
1214  q2 = rpos[1] * sa;
1215  q3 = rpos[2] * sa;
1216  q4 = cos(angle/2.);
1217  q11 = q1 * q1;
1218  q12 = q1 * q2;
1219  q13 = q1 * q3;
1220  q14 = q1 * q4;
1221  q22 = q2 * q2;
1222  q23 = q2 * q3;
1223  q24 = q2 * q4;
1224  q33 = q3 * q3;
1225  q34 = q3 * q4;
1226 
1227  opos[0] = ipos[0] *(1.-2.*(q22+q33)) + ipos[1] * 2.*(q12-q34) + ipos[2] * 2.*(q13+q24);
1228  opos[1] = ipos[0]*2.*(q12+q34)+ipos[1]*(1.-2.*(q11+q33))+ipos[2]*2.*(q23-q14);
1229  opos[2] = ipos[0]*2.*(q13-q24)+ipos[1]*2.*(q14+q23)+ipos[2]*(1.-2.*(q11+q22));
1230 
1231 }
png_uint_32 length
Definition: png.c:2173
avector a_quaternion2euler ( quaternion  q)
1257 {
1258  avector rpw;
1259 
1260  normalize_q(&q);
1261  /*
1262 rpw.b = atan2(q.d.y*q.d.z+q.w*q.d.x,q.w*q.w+q.d.z*q.d.z-.5);
1263 rpw.e = asin(-2.*(q.d.x*q.d.z-q.w*q.d.y));
1264 rpw.h = atan2(q.d.x*q.d.y+q.w*q.d.z,q.w*q.w+q.d.x*q.d.x-.5);
1265 */
1266  // double sqw = q.w * q.w;
1267  double sqx = q.d.x * q.d.x;
1268  double sqy = q.d.y * q.d.y;
1269  double sqz = q.d.z * q.d.z;
1270  rpw.b = atan2(2.*(q.d.z*q.d.y + q.d.x*q.w), 1. - 2.*(sqx + sqy));
1271  rpw.e = asin(-2.*(q.d.x*q.d.z - q.d.y*q.w));
1272  rpw.h = atan2(2.*(q.d.x*q.d.y + q.d.z*q.w), 1. - 2.*(sqy + sqz));
1273 
1274  return (rpw);
1275 }
double y
Y value.
Definition: vector.h:114
cvector d
Orientation.
Definition: vector.h:405
double x
X value.
Definition: vector.h:112
double e
Elevation.
Definition: vector.h:282
void normalize_q(quaternion *q)
Definition: vector.cpp:961
double b
Bank.
Definition: vector.h:284
3 element attitude vector.
Definition: vector.h:277
double w
Rotation.
Definition: vector.h:407
double z
Z value.
Definition: vector.h:116
double h
Heading.
Definition: vector.h:280