COSMOS core  1.0.2 (beta)
Comprehensive Open-architecture Solution for Mission Operations Systems
vector.h
Go to the documentation of this file.
1 /********************************************************************
2 * Copyright (C) 2015 by Interstel Technologies, Inc.
3 * and Hawaii Space Flight Laboratory.
4 *
5 * This file is part of the COSMOS/core that is the central
6 * module for COSMOS. For more information on COSMOS go to
7 * <http://cosmos-project.com>
8 *
9 * The COSMOS/core software is licenced under the
10 * GNU Lesser General Public License (LGPL) version 3 licence.
11 *
12 * You should have received a copy of the
13 * GNU Lesser General Public License
14 * If not, go to <http://www.gnu.org/licenses/>
15 *
16 * COSMOS/core is free software: you can redistribute it and/or
17 * modify it under the terms of the GNU Lesser General Public License
18 * as published by the Free Software Foundation, either version 3 of
19 * the License, or (at your option) any later version.
20 *
21 * COSMOS/core is distributed in the hope that it will be useful, but
22 * WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 * Lesser General Public License for more details.
25 *
26 * Refer to the "licences" folder for further information on the
27 * condititons and terms to use this software.
28 ********************************************************************/
29 
30 #ifndef _MATH_VECTOR_H
31 #define _MATH_VECTOR_H
32 
33 //#include "types.h"
34 #include "support/configCosmos.h"
35 #include "constants.h"
36 
37 #include <iostream>
38 #include <iomanip> // std::setw
39 #include <cmath>
40 #include <vector>
41 
42 #ifdef _MSC_BUILD
43 #include <stdint.h> // for uint16_t et all.
44 #endif
45 
47 
49 // TODO: rename to row_vector
50 // TODO: create a generic type of vector like: vector3 that can be accessed wither by .x, .y, .z or with [0], [1], [2]
51 // TODO: consider using Eigen, no because Eigen is a heavily templated library and takes a long time to compile and has way more than needed
52 // it can be used for specific projects that require it
53 struct rvector
54 {
55  double col[3] = {0.};
56 
57  rvector() {}
58  rvector(double d0, double d1, double d2) {
59  col[0] = d0;
60  col[1] = d1;
61  col[2] = d2;
62  }
63 
65 
69  vector<double> v_col = vector<double>(col, col+sizeof(col)/sizeof(col[0]));
70  return json11::Json::object {
71  { "col" , v_col }
72  };
73  }
75 
80  void from_json(const string& s) {
81  string error;
82  json11::Json parsed = json11::Json::parse(s,error);
83  if(error.empty()) {
84  auto p_col = parsed["col"].array_items();
85  for(size_t i = 0; i != p_col.size(); ++i) {
86  if(!p_col[i].is_null()) col[i] = p_col[i].number_value();
87  }
88  } else {
89  cerr<<"ERROR: <"<<error<<">"<<endl;
90  }
91  return;
92  }
93 };
94 
95 std::ostream& operator << (std::ostream& out, const rvector& a);
96 std::ostream& operator << (std::ostream& out, const vector<rvector>& a);
97 std::istream& operator >> (std::istream& out, rvector& a);
98 rvector operator * (rvector v, double scalar); // multiply vector by vector operator
99 rvector operator * (rvector v1, rvector v2); // multiply vector by vector operator
100 rvector operator / (rvector v, double scalar); // divide vector by scalar operator
101 bool operator == (rvector a, rvector b); // Compares two vectors
102 bool operator != (rvector a, rvector b); // Compares two vectors
103 
105 
107 class cvector
108 {
109 
110 public:
112  double x = 0.;
114  double y = 0.;
116  double z = 0.;
117 
118  cvector() {}
119  cvector(double tx, double ty, double tz) {
120  x = tx;
121  y = ty;
122  z = tz;
123  }
124 
125  void normalize(double scale=1.);
126  double length();
127  double norm();
128  double norm2();
129  cvector normalized(double scale=1.);
130  double& operator[] (const int index);
131 
133 
137  return json11::Json::object {
138  { "x" , x },
139  { "y" , y },
140  { "z" , z }
141  };
142  }
143 
145 
150  void from_json(const string& s) {
151  string error;
152  json11::Json parsed = json11::Json::parse(s,error);
153  if(error.empty()) {
154  if(!parsed["x"].is_null()) x = parsed["x"].number_value();
155  if(!parsed["y"].is_null()) y = parsed["y"].number_value();
156  if(!parsed["z"].is_null()) z = parsed["z"].number_value();
157  } else {
158  cerr<<"ERROR: <"<<error<<">"<<endl;
159  }
160  return;
161  }
162 };
163 
165 
167 struct svector
168 {
170  double phi = 0.;
172  double lambda = 0.;
174  double r = 0.;
175 
176  svector() {}
177  svector(double tphi, double tlambda, double tr) {
178  phi = tphi;
179  lambda = tlambda;
180  r = tr;
181  }
182 
184 
188  return json11::Json::object {
189  { "phi" , phi },
190  { "lambda" , lambda },
191  { "r" , r }
192  };
193  }
194 
196 
201  void from_json(const string& s) {
202  string error;
203  json11::Json parsed = json11::Json::parse(s,error);
204  if(error.empty()) {
205  if(!parsed["phi"].is_null()) phi = parsed["phi"].number_value();
206  if(!parsed["lambda"].is_null()) lambda = parsed["lambda"].number_value();
207  if(!parsed["r"].is_null()) r = parsed["r"].number_value();
208  } else {
209  cerr<<"ERROR: <"<<error<<">"<<endl;
210  }
211  return;
212  }
213 } ;
214 
215 std::ostream& operator << (std::ostream& out, const svector& a);
216 std::istream& operator >> (std::istream& out, svector& a);
217 
219 
221 // TODO: replace name gvector->geodetic
222 struct gvector
223 {
225  double lat = 0.;
227  double lon = 0.;
229  double h = 0.;
230 
231  gvector() {}
232  gvector(double tlat, double tlon, double th) {
233  lat = tlat;
234  lon = tlon;
235  h = th;
236  }
237 
239 
243  return json11::Json::object {
244  { "lat" , lat },
245  { "lon" , lon },
246  { "h" , h }
247  };
248  }
249 
251 
256  void from_json(const string& s) {
257  string error;
258  json11::Json parsed = json11::Json::parse(s,error);
259  if(error.empty()) {
260  if(!parsed["lat"].is_null()) lat = parsed["lat"].number_value();
261  if(!parsed["lon"].is_null()) lon = parsed["lon"].number_value();
262  if(!parsed["h"].is_null()) h = parsed["h"].number_value();
263  } else {
264  cerr<<"ERROR: <"<<error<<">"<<endl;
265  }
266  return;
267  }
268 };
269 
270 std::ostream& operator << (std::ostream& out, const gvector& a);
271 std::istream& operator >> (std::istream& out, gvector& a);
272 
274 
276 // TODO: change name to something more explicit
277 struct avector
278 {
280  double h = 0.;
282  double e = 0.;
284  double b = 0.;
285 
286  avector() {}
287  avector(double th, double te, double tb) {
288  h = th;
289  e = te;
290  b = tb;
291  }
292 
294 
298  return json11::Json::object {
299  { "h" , h },
300  { "e" , e },
301  { "b" , b }
302  };
303  }
304 
306 
311  void from_json(const string& s) {
312  string error;
313  json11::Json parsed = json11::Json::parse(s,error);
314  if(error.empty()) {
315  if(!parsed["h"].is_null()) h = parsed["h"].number_value();
316  if(!parsed["e"].is_null()) e = parsed["e"].number_value();
317  if(!parsed["b"].is_null()) b = parsed["b"].number_value();
318  } else {
319  cerr<<"ERROR = "<<error<<endl;
320  }
321  return;
322  }
323 } ;
324 
325 std::ostream& operator << (std::ostream& out, const avector& a);
326 std::istream& operator >> (std::istream& out, avector& a);
327 
328 std::ostream& operator << (std::ostream& out, const cvector& a);
329 std::istream& operator >> (std::istream& in, cvector& a);
330 
331 // Geodetic Vector operations
332 gvector gv_zero();
333 
334 // Row Vector operations
335 rvector rv_zero();
338 rvector rv_unitx(double scale=1.);
339 rvector rv_unity(double scale=1.);
340 rvector rv_unitz(double scale=1.);
341 rvector rv_one();
342 rvector rv_one(double x, double y, double z);
343 rvector rv_smult(double a, rvector b);
346 rvector rv_sadd(double a, rvector b);
354 
355 double norm_rv(rvector a);
356 
357 void normalize_rv(rvector &v);
358 
359 double sep_rv(rvector v1, rvector v2);
360 //double sep_rv2(rvector v1, rvector v2);
361 double dot_rv(rvector a, rvector b);
362 double length_rv(rvector v);
363 bool equal_rv(rvector v1, rvector v2);
364 double sum_rv(rvector a);
365 
366 
368 
369 
370 // Column Vector operations
371 
372 cvector cv_zero();
373 cvector cv_unitx();
374 cvector cv_unity();
375 cvector cv_unitz();
376 cvector cv_one();
379 cvector cv_sadd(double a, cvector b);
384 cvector cv_smult(double a, cvector b);
386 void normalize_cv(cvector &v);
387 
388 double sep_cv(cvector v1, cvector v2);
389 double dot_cv(cvector a, cvector b);
390 double length_cv(cvector v);
391 double norm_cv(cvector v);
392 double cv_norm(cvector v);
393 double sum_cv(cvector a);
394 
396 
401 // TODO: replace cvector with x,y,z
403 {
407  double w = 0.;
408 
410  quaternion(cvector td, double tw) {
411  d = td;
412  w = tw;
413  }
414 
416 
420  return json11::Json::object {
421  { "d" , d },
422  { "w" , w }
423  };
424  }
426 
431  void from_json(const string& s) {
432  string error;
433  json11::Json parsed = json11::Json::parse(s,error);
434  if(error.empty()) {
435  if(!parsed["d"].is_null()) d.from_json(parsed["d"].dump());
436  if(!parsed["w"].is_null()) w = parsed["w"].number_value();
437  } else {
438  cerr<<"ERROR: <"<<error<<">"<<endl;
439  }
440  return;
441  }
442 } ;
443 
444 std::ostream& operator << (std::ostream& out, const quaternion& a);
445 std::istream& operator >> (std::istream& out, quaternion& a);
446 
448 
450 struct qcomplex
451 {
452  double i = 0.;
453  double j = 0.;
454  double k = 0.;
455  double r = 0.;
456 
457  qcomplex() {}
458  qcomplex(double ti, double tj, double tk, double tr) {
459  i = ti;
460  j = tj;
461  k = tk;
462  r = tr;
463  }
464 
466 
470  return json11::Json::object {
471  { "i" , i },
472  { "j" , j },
473  { "k" , k },
474  { "r" , r }
475  };
476  }
477 
479 
484  void from_json(const string& s) {
485  string error;
486  json11::Json parsed = json11::Json::parse(s,error);
487  if(error.empty()) {
488  if(!parsed["i"].is_null()) i = parsed["i"].number_value();
489  if(!parsed["j"].is_null()) j = parsed["j"].number_value();
490  if(!parsed["k"].is_null()) k = parsed["k"].number_value();
491  if(!parsed["r"].is_null()) r = parsed["r"].number_value();
492  } else {
493  cerr<<"ERROR: <"<<error<<">"<<endl;
494  }
495  return;
496  }
497 };
498 
499 std::ostream& operator << (std::ostream& out, const qcomplex& a);
500 std::istream& operator >> (std::istream& out, qcomplex& a);
501 
503 
506 struct qlast
507 {
508  double q1 = 0.; // x
509  double q2 = 0.; // y
510  double q3 = 0.; // z
511  double q4 = 0.; // w
512 
513  qlast() {}
514  qlast(double tq1, double tq2, double tq3, double tq4) {
515  q1 = tq1;
516  q2 = tq2;
517  q3 = tq3;
518  q4 = tq4;
519  }
520 
522 
526  return json11::Json::object {
527  { "q1" , q1 },
528  { "q2" , q2 },
529  { "q3" , q3 },
530  { "q4" , q4 }
531  };
532  }
533 
535 
540  void from_json(const string& s) {
541  string error;
542  json11::Json parsed = json11::Json::parse(s,error);
543  if(error.empty()) {
544  if(!parsed["q1"].is_null()) q1 = parsed["q1"].number_value();
545  if(!parsed["q2"].is_null()) q2 = parsed["q2"].number_value();
546  if(!parsed["q3"].is_null()) q3 = parsed["q3"].number_value();
547  if(!parsed["q4"].is_null()) q4 = parsed["q4"].number_value();
548  } else {
549  cerr<<"ERROR: <"<<error<<">"<<endl;
550  }
551  return;
552  }
553 };
554 
555 std::ostream& operator << (std::ostream& out, const qlast& a);
556 std::istream& operator >> (std::istream& out, qlast& a);
557 
559 
562 struct qfirst
563 {
564  double q0; // w
565  double q1; // x
566  double q2; // y
567  double q3; // z
568 
569  qfirst() {}
570  qfirst(double tq0, double tq1, double tq2, double tq3) {
571  q0 = tq0;
572  q1 = tq1;
573  q2 = tq2;
574  q3 = tq3;
575  }
576 
578 
582  return json11::Json::object {
583  { "q0" , q0 },
584  { "q1" , q1 },
585  { "q2" , q2 },
586  { "q3" , q3 }
587  };
588  }
589 
591 
596  void from_json(const string& s) {
597  string error;
598  json11::Json parsed = json11::Json::parse(s,error);
599  if(error.empty()) {
600  if(!parsed["q0"].is_null()) q0 = parsed["q0"].number_value();
601  if(!parsed["q1"].is_null()) q1 = parsed["q1"].number_value();
602  if(!parsed["q2"].is_null()) q2 = parsed["q2"].number_value();
603  if(!parsed["q3"].is_null()) q3 = parsed["q3"].number_value();
604  } else {
605  cerr<<"ERROR: <"<<error<<">"<<endl;
606  }
607  return;
608  }
609 };
610 
611 std::ostream& operator << (std::ostream& out, const qfirst& a);
612 std::istream& operator >> (std::istream& out, qfirst& a);
613 
615 void normalize_q(quaternion *q);
624 quaternion q_smult(double a, quaternion q);
630 
632 
633 quaternion q_change_around_cv(cvector around, double angle);
634 quaternion q_change_around_rv(rvector around, double angle);
635 
636 quaternion q_change_around_x(double angle);
637 quaternion q_change_around_y(double angle);
638 quaternion q_change_around_z(double angle);
639 
640 // TODO: check this function, does not seem to be implemented
641 //quaternion q_rotate_around(int axis, double angle);
642 
643 quaternion q_irotate_for(rvector sourcea, rvector sourceb, rvector targeta, rvector targetb);
644 quaternion q_eye();
646 quaternion q_evaluate_poly(double x, vector< vector<double> > parms);
647 quaternion q_evaluate_poly_slope(double x, vector< vector<double> > parms);
648 quaternion q_evaluate_poly_accel(double x, vector< vector<double> > parms);
649 quaternion q_evaluate_poly_jerk(double x, vector< vector<double> > parms);
650 
651 double length_q(quaternion q);
652 double norm_q(quaternion q);
653 double sep_q(quaternion q1, quaternion q2);
654 double inner_q(quaternion q1, quaternion q2);
655 
656 void qrotate(double ipos[3], double rpos[3], double angle, double *opos);
658 
659 // TODO: bring these functions from mathlib
662 //cvector rotate_q(quaternion q, rvector v);
663 //cvector rotate_q(quaternion q, cvector v);
664 //cvector irotate(quaternion q,cvector v); // doesn't exist in .cpp?
665 
666 namespace Cosmos {
667  namespace Math {
668  namespace Vectors {
670 
672  class Vector
673  {
674 
675  public:
676 
679 
680  explicit Vector(double x0=0., double y0=0., double z0=0., double w0=0.)
681  {
682  x = x0;
683  y = y0;
684  z = z0;
685  w = w0;
686  }
687 
688  explicit Vector(rvector rv)
689  {
690  x = rv.col[0];
691  y = rv.col[1];
692  z = rv.col[2];
693  w = 0.;
694  }
695 
696  explicit Vector(quaternion q)
697  {
698  x = q.d.x;
699  y = q.d.y;
700  z = q.d.z;
701  w = q.w;
702  }
703 
704  explicit Vector(cvector cv)
705  {
706  x = cv.x;
707  y = cv.y;
708  z = cv.z;
709  w = 0.;
710  }
711 
712  double x;
713  double y;
714  double z;
715  double w;
716 
717  // TODO: check if we can iterated the vector
718  double at(int i);
719  // convert from cartesian vector to row vector
720 // Vector from_cv(cvector cv);
721 // Vector from_rv(rvector rv);
722 // Vector from_q(quaternion q);
723  rvector to_rv();
724  cvector to_cv();
725  quaternion to_q();
726  Vector cross(Vector b);
727  double dot(Vector b);
728  Vector &normalize(double size=1.);
729  Vector &clear(double x0=0., double y0=0., double z0=0., double w0=0.);
730  double norm();
731  double separation(Vector b);
732  double area(Vector b);
733  Vector vector();
734  Vector flattenx();
735  Vector flatteny();
736  Vector flattenz();
737  double sum();
738 
739  Vector &operator = (const rvector rv)
740  {
741  *this = Vector(rv);
742  return *this;
743  }
744 
745  double &operator [] (const int &index);
746 
747  Vector operator *(const double scale) const; // multiply vector by scalar operator
748  Vector &operator *=( const double &scale); // multiply vector by scalar operator in place
749  Vector operator * (const Vector &v2) const; // multiply vector by vector operator
750 
751  Vector operator / (const double scale) const; // divide vector by scalar operator
752  Vector &operator /= (const double &scale); // divide vector by scalar operator in place
753 
754  Vector operator - (const Vector &v2) const; // Subtract vector by vector operator
755  Vector &operator -= (const Vector &v2); // subtract vector by vector operator in place
756  Vector operator - () const; // Negate vector operator
757 
758  Vector operator + (const Vector &v2) const; // add vector by vector operator
759  Vector &operator += (const Vector &v2); // add vector by vector operator in place
760 
761  bool operator == (const Vector &v2) const; // Compares two vectors
762  bool operator != (const Vector &v2) const; // Compares two vectors
763 
765 
769  return json11::Json::object {
770  { "x" , x },
771  { "y" , y },
772  { "z" , z },
773  { "w" , w }
774  };
775  }
776 
778 
783  void from_json(const string& s) {
784  string error;
785  json11::Json parsed = json11::Json::parse(s,error);
786  if(error.empty()) {
787  if(!parsed["x"].is_null()) x = parsed["x"].number_value();
788  if(!parsed["y"].is_null()) y = parsed["y"].number_value();
789  if(!parsed["z"].is_null()) z = parsed["z"].number_value();
790  if(!parsed["w"].is_null()) w = parsed["w"].number_value();
791  } else {
792  cerr<<"ERROR: <"<<error<<">"<<endl;
793  }
794  return;
795  }
796  };
797 
798  Vector operator * (const double scale, const Vector &v);
799  std::ostream& operator << (std::ostream& out, const Vector& v);
800  Vector eye(double scale=1.);
801  Vector unitxV(double scale=1.);
802  Vector unityV(double scale=1.);
803  Vector unitzV(double scale=1.);
804 
805  class geodeticVector : public Vector {};
806 
807  class sphericalVector : public Vector {};
808 
809  class eulerVector : public Vector {};
810  }
811 
812 
813  namespace Quaternions {
815  {
816 
817  public:
818 
819  explicit Quaternion(double qx=0., double qy=0., double qz=0., double qw=0.) : Vector(qx, qy, qz, qw)
820  {
821  x = qx;
822  y = qy;
823  z = qz;
824  w = qw;
825  }
826 
827  explicit Quaternion(Vector v)
828  {
829  x = v.x;
830  y = v.y;
831  z = v.z;
832  w = 0.;
833  }
834 
835  explicit Quaternion(quaternion q)
836  {
837  x = q.d.x;
838  y = q.d.y;
839  z = q.d.z;
840  w = q.w;
841  }
842 
843  explicit Quaternion(rvector rv) : Vector(rv)
844  {
845  x = rv.col[0];
846  y = rv.col[1];
847  z = rv.col[2];
848  w = 0.;
849  }
850 
851  quaternion to_q();
852  Quaternion getQuaternion();
853 
854  // temporary while the new Quaternion class is not finisheds
855  Quaternion quaternion2Quaternion(quaternion q);
856  quaternion Quaternion2quaternion(Quaternion Q);
857 
858 
859  // operators
860 // Quaternion &operator = (const Quaternion &q) { return *this; }
861  Quaternion &operator = (const quaternion &q2);
862  Quaternion operator * (const double scale) const; // multiply vector by scalar operator
863  Quaternion &operator *= ( const double scale); // multiply vector by scalar operator in place
864  Quaternion operator * (const Quaternion &q2) const;
865 
866 // Quaternion operator / (double scale); // multiply vector by scalar operator
867 // Quaternion &operator /= (const double &scale); // multiply vector by scalar operator in place
868 
869  Quaternion operator - (const Quaternion &q2) const; // Subtract vector by vector operator
870  Quaternion &operator -= (const Quaternion &q2); // subtract vector by vector operator in place
871  Quaternion operator - () const; // Negate vector operator
872 
873  Quaternion operator + (const Quaternion &q2); // add vector by vector operator
874  Quaternion &operator += (const Quaternion &q2); // add vector by vector operator in place
875  //std::ostream& operator<<(std::ostream& os, const Quaternion& q);
876  //friend std::ostream& operator << (std::ostream& os, const Quaternion& q);
877  //std::istream& operator >> (std::istream& out, Quaternion& a);
878 
879  Quaternion multiplyScalar(double a);
880  Quaternion conjugate() const;
881  Vector vector();
882  Vector omegaFromDerivative(Quaternion dq);
883 // Quaternion &normalize();
884 // double norm();
885  Vector toEuler();
886  Vector irotate(const Vector &v);
887  Vector drotate(const Vector &v);
888 
890 
894  return json11::Json::object {
895  { "x" , x },
896  { "y" , y },
897  { "z" , z },
898  { "w" , w }
899  };
900  }
901 
903 
908  void from_json(const string& s) {
909  string error;
910  json11::Json parsed = json11::Json::parse(s,error);
911  if(error.empty()) {
912  if(!parsed["x"].is_null()) x = parsed["x"].number_value();
913  if(!parsed["y"].is_null()) y = parsed["y"].number_value();
914  if(!parsed["z"].is_null()) z = parsed["z"].number_value();
915  if(!parsed["w"].is_null()) w = parsed["w"].number_value();
916  } else {
917  cerr<<"ERROR: <"<<error<<">"<<endl;
918  }
919  return;
920  }
921 
922  };
923 
924  // declared outside class because it does not need to access members of the class Quaternion
925  Quaternion operator * (double scale, const Quaternion &q);
926  Quaternion operator * (const Vectors::Vector &v, const Quaternion &q);
927  std::ostream& operator << (std::ostream& os, const Quaternion& q);
930  Quaternion drotate_around_x(double angle);
931  Quaternion drotate_around_y(double angle);
932  Quaternion drotate_around_z(double angle);
933  Quaternion drotate_around(int axis, double angle);
934  Quaternion eye(double scale = 1.);
935 
936  }
937  } // end namespace Math
938 } // end namespace COSMOS
939 
940 #endif // _MATH_VECTOR_H
json11::Json to_json() const
Convert class contents to JSON object.
Definition: vector.h:525
void from_json(const string &s)
Set class contents from JSON string.
Definition: vector.h:484
double y
Y value.
Definition: vector.h:114
Vector(rvector rv)
Definition: vector.h:688
Definition: agentclass.cpp:54
double inner_q(quaternion q1, quaternion q2)
Inner product of two quaternions.
Definition: vector.cpp:1047
void from_json(const string &s)
Set class contents from JSON string.
Definition: vector.h:540
gvector()
Definition: vector.h:231
std::map< std::string, Json > object
Definition: json11.hpp:88
Definition: vector.h:809
quaternion q_change_around_cv(cvector around, double angle)
Create rotation quaternion from axis and angle.
Definition: vector.cpp:1372
cvector cv_normal(cvector v)
Normalize cartesian vector.
Definition: vector.cpp:463
void normalize_q(quaternion *q)
Definition: vector.cpp:961
svector(double tphi, double tlambda, double tr)
Definition: vector.h:177
Definition: eci2kep_test.cpp:33
Definition: eci2kep_test.cpp:33
rvector rv_normalto(rvector p0, rvector p1, rvector p2)
Normal to a polygon.
Definition: mathlib.cpp:354
Quaternion, scalar first using vector elements.
Definition: vector.h:562
Definition: json11.hpp:79
rvector()
Definition: vector.h:57
Quaternion drotate_around_x(double angle)
Rotation Quaternion for X axis.
Definition: vector.cpp:2580
double length_q(quaternion q)
Length of quaternion.
Definition: vector.cpp:1329
rvector rv_convert(svector from)
Convert svector to rvector.
Definition: vector.cpp:86
rvector rv_add(rvector a, rvector b)
Add two row vectors.
Definition: vector.cpp:299
svector()
Definition: vector.h:176
double norm_q(quaternion q)
Definition: vector.cpp:956
y
Definition: inputfile.py:6
cvector cv_unitx()
Unit x vector.
Definition: vector.cpp:422
json11::Json to_json() const
Convert class contents to JSON object.
Definition: vector.h:242
3 element generic row vector
Definition: vector.h:53
int i
Definition: rw_test.cpp:37
double sep_rv(rvector v1, rvector v2)
Angular separation between row vectors.
Definition: vector.cpp:42
Quaternion, scalar last, using vector elements.
Definition: vector.h:506
quaternion q_eye()
Identity quaternion.
Definition: vector.cpp:1310
qlast(double tq1, double tq2, double tq3, double tq4)
Definition: vector.h:514
cvector d
Orientation.
Definition: vector.h:405
quaternion q_rmult(quaternion q1, quaternion q2)
Definition: vector.cpp:1133
double length_rv(rvector v)
Length of row vector.
Definition: vector.cpp:748
cvector cv_div(cvector a, cvector b)
Divide two vectors.
Definition: vector.cpp:586
quaternion q_change_between_cv(cvector from, cvector to)
Create rotation quaternion from 2 vectors.
Definition: mathlib.cpp:2350
Quaternion, scalar last, using x, y, z.
Definition: vector.h:402
double sum_rv(rvector a)
Sum elements of a row vector.
Definition: vector.cpp:775
quaternion q_euler2quaternion(avector rpw)
Definition: vector.cpp:1233
cvector cv_cross(cvector a, cvector b)
Take cross product of two vectors.
Definition: vector.cpp:613
cvector cv_sub(cvector a, cvector b)
Subtract two vectors.
Definition: vector.cpp:570
void normalize_rv(rvector &v)
Normalize row order vector in place.
Definition: vector.cpp:222
double y
Definition: vector.h:713
rvector operator/(rvector v, double scalar)
Definition: vector.cpp:857
cvector()
Definition: vector.h:118
cvector cv_add(cvector a, cvector b)
Add two vectors.
Definition: vector.cpp:554
rvector(double d0, double d1, double d2)
Definition: vector.h:58
qfirst()
Definition: vector.h:569
void from_json(const string &s)
Set class contents from JSON string.
Definition: vector.h:311
quaternion q_change_around_y(double angle)
Rotation quaternion for Y axis.
Definition: vector.cpp:1435
double q1
Definition: vector.h:565
rvector operator*(rvector v, double scalar)
Definition: vector.cpp:839
quaternion q_change_around_x(double angle)
Rotation quaternion for X axis.
Definition: vector.cpp:1410
double x
X value.
Definition: vector.h:112
Quaternion(rvector rv)
Definition: vector.h:843
json11::Json to_json() const
Convert class contents to JSON object.
Definition: vector.h:469
quaternion q_axis2quaternion_rv(rvector v)
Row vector axis and angle to Quaternion.
Definition: mathlib.cpp:260
avector()
Definition: vector.h:286
quaternion q_evaluate_poly_accel(double x, vector< vector< double > > parms)
Evaluate quaternion polynomial acceleration.
Definition: mathlib.cpp:1369
rvector rv_one()
Row vector of ones.
Definition: vector.cpp:151
long b
Definition: jpegint.h:371
json11::Json to_json() const
Convert class contents to JSON object.
Definition: vector.h:187
json11::Json to_json() const
Convert class contents to JSON object.
Definition: vector.h:768
rvector rv_smult(double a, rvector b)
Multiply row vector by scalar.
Definition: vector.cpp:266
json11::Json to_json() const
Convert class contents to JSON object.
Definition: vector.h:419
quaternion q_smult(double a, quaternion q)
Multiply quaternion by scalar.
Definition: vector.cpp:1151
void qrotate(double ipos[3], double rpos[3], double angle, double *opos)
Definition: vector.cpp:1199
quaternion q_evaluate_poly_jerk(double x, vector< vector< double > > parms)
Evaluate quaternion polynomial jerk.
Definition: mathlib.cpp:1400
quaternion q_change_around_z(double angle)
Rotation quaternion for Z axis.
Definition: vector.cpp:1461
double z
Definition: vector.h:714
Vector unitxV(double scale)
Definition: vector.cpp:2075
quaternion q_axis2quaternion_cv(cvector v)
Definition: vector.cpp:1282
rvector rv_unity(double scale=1.)
Scaled y row vector.
Definition: vector.cpp:129
void dump(std::string &out) const
quaternion q_change_between_rv(rvector from, rvector to)
Definition: mathlib.cpp:2388
double dot_rv(rvector a, rvector b)
Dot product of two row vectors.
Definition: vector.cpp:379
qcomplex()
Definition: vector.h:457
quaternion q_drotate_between_rv(rvector from, rvector to)
Create rotation quaternion from 2 row vectors.
Definition: mathlib.cpp:81
qlast()
Definition: vector.h:513
void from_json(const string &s)
Set class contents from JSON string.
Definition: vector.h:783
cvector(double tx, double ty, double tz)
Definition: vector.h:119
json11::Json to_json() const
Convert class contents to JSON object.
Definition: vector.h:893
json11::Json to_json() const
Convert class contents to JSON object.
Definition: vector.h:136
avector(double th, double te, double tb)
Definition: vector.h:287
std::istream & operator>>(std::istream &out, rvector &a)
Definition: vector.cpp:831
static Json parse(const std::string &in, std::string &err, JsonParse strategy=JsonParse::STANDARD)
Quaternion(Vector v)
Definition: vector.h:827
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
3 element attitude vector.
Definition: vector.h:277
double q0
Definition: vector.h:564
quaternion q_irotate_for(rvector sourcea, rvector sourceb, rvector targeta, rvector targetb)
Create irotate quaternion from two orthogonal vectors.
Definition: mathlib.cpp:154
rvector rv_normal(rvector v)
Normalize row order vector.
Definition: vector.cpp:212
3 element spherical vector
Definition: vector.h:167
std::ostream & operator<<(std::ostream &out, const rvector &a)
Definition: vector.cpp:800
Headers and definitions common to all COSMOS.
svector s_convert(rvector from)
Convert rvector to svector.
Definition: vector.cpp:66
const array & array_items() const
Definition: json11.cpp:284
double x
Definition: vector.h:712
void normalize_cv(cvector &v)
Normalize cartesian vector in place, i.e. divides it by its own norm.
Definition: vector.cpp:474
void from_json(const string &s)
Set class contents from JSON string.
Definition: vector.h:431
void from_json(const string &s)
Set class contents from JSON string.
Definition: vector.h:150
quaternion q_times(quaternion q1, quaternion q2)
Multiply the elements of 2 quaternions.
Definition: vector.cpp:1028
rvector rv_mult(rvector a, rvector b)
Multiply two row vectors.
Definition: vector.cpp:347
rvector rv_shortest(rvector v)
Shortest vector.
Definition: vector.cpp:177
json11::Json to_json() const
Convert class contents to JSON object.
Definition: vector.h:581
bool operator!=(rvector a, rvector b)
Definition: vector.cpp:876
cvector cv_zero()
Zero cartesian vector.
Definition: vector.cpp:412
x
Definition: inputfile.py:6
rvector rv_unitz(double scale=1.)
Scaled z row vector.
Definition: vector.cpp:140
gvector gv_zero()
Zero geodetic vector.
Definition: vector.cpp:946
quaternion q_add(quaternion q1, quaternion q2)
Add two quaternions.
Definition: vector.cpp:1168
double w
Rotation.
Definition: vector.h:407
quaternion q_zero()
Zero quaternion.
Definition: vector.cpp:1003
quaternion q_evaluate_poly_slope(double x, vector< vector< double > > parms)
Evaluate quaternion polynomial slope.
Definition: mathlib.cpp:1338
double sep_cv(cvector v1, cvector v2)
Angular separation between vectors.
Definition: vector.cpp:390
rvector rv_zero()
Zero row order vector.
Definition: vector.cpp:107
Definition: eci2kep_test.cpp:33
double q3
Definition: vector.h:567
bool operator==(rvector a, rvector b)
Definition: vector.cpp:863
void from_json(const string &s)
Set class contents from JSON string.
Definition: vector.h:201
cvector cv_unitz()
Unit z vector.
Definition: vector.cpp:442
Matrix eye(double scale)
Scaled Identity ::Matrix.
Definition: matrix.cpp:2025
Quaternion(double qx=0., double qy=0., double qz=0., double qw=0.)
Definition: vector.h:819
rvector rv_sqrt(rvector a)
Row vector square root.
Definition: vector.cpp:786
cvector cv_unity()
Unit y vector.
Definition: vector.cpp:432
double length_cv(cvector v)
Definition: vector.cpp:638
quaternion q_sqrt(quaternion q1)
Square root of the elements of a quaternion.
Definition: vector.cpp:1060
Vector unityV(double scale)
Definition: vector.cpp:2082
avector a_quaternion2euler(quaternion q)
Definition: vector.cpp:1256
double z
Z value.
Definition: vector.h:116
rvector rv_div(rvector a, rvector b)
Divide two row vectors.
Definition: vector.cpp:331
Vector(double x0=0., double y0=0., double z0=0., double w0=0.)
Definition: vector.h:680
cvector cv_quaternion2axis(quaternion q)
Definition: vector.cpp:1342
qcomplex(double ti, double tj, double tk, double tr)
Definition: vector.h:458
void from_json(const string &s)
Set class contents from JSON string.
Definition: vector.h:908
double sum_cv(cvector a)
Definition: vector.cpp:708
png_uint_32 length
Definition: png.c:2173
cvector cv_one()
Vector of ones.
Definition: vector.cpp:452
quaternion()
Definition: vector.h:409
Quaternion drotate_between(Vectors::Vector a, Vectors::Vector b)
Definition: vector.cpp:2494
bool equal_rv(rvector v1, rvector v2)
Boolean equate of row vetor.
Definition: vector.cpp:735
quaternion q_sub(quaternion q1, quaternion q2)
Subtract two quaternions.
Definition: vector.cpp:1186
double col[3]
Definition: vector.h:55
cvector cv_sqrt(cvector a)
Definition: vector.cpp:717
double q2
Definition: vector.h:566
Vector(quaternion q)
Definition: vector.h:696
rvector irotate(quaternion q, rvector v)
Indirectly rotate a row vector using a quaternion.
Definition: mathlib.cpp:2308
quaternion q_identity()
Definition: vector.cpp:1317
Quaternion drotate_around(int axis, double angle)
Rotation Quaternion for indicated axis.
Definition: vector.cpp:2641
quaternion q_fmult(rvector r1, quaternion q2)
rvector quaternion multiply
Definition: vector.cpp:1079
quaternion q_conjugate(quaternion q)
Definition: vector.cpp:1010
void from_json(const string &s)
Set class contents from JSON string.
Definition: vector.h:80
json11::Json to_json() const
Convert class contents to JSON object.
Definition: vector.h:297
Quaternion irotate_for(Vectors::Vector sourcea, Vectors::Vector sourceb, Vectors::Vector targeta, Vectors::Vector targetb)
Create irotate quaternion from two orthogonal vectors.
Definition: vector.cpp:2540
void from_json(const string &s)
Set class contents from JSON string.
Definition: vector.h:596
gvector(double tlat, double tlon, double th)
Definition: vector.h:232
Quaternion(quaternion q)
Definition: vector.h:835
json11::Json to_json() const
Convert class contents to JSON object.
Definition: vector.h:68
quaternion q_mult(quaternion q1, quaternion q2)
Definition: vector.cpp:1119
Vector Class.
Definition: vector.h:672
rvector rv_shortest2(rvector v)
Definition: vector.cpp:192
cvector cv_smult(double a, cvector b)
Multiply vector by scalar.
Definition: vector.cpp:521
rvector rv_unitx(double scale=1.)
Scaled x row vector.
Definition: vector.cpp:118
double norm_rv(rvector a)
Infinite norm of row vector.
Definition: vector.cpp:765
3 element geodetic vector
Definition: vector.h:222
rvector rv_sub(rvector a, rvector b)
Subtract two vectors.
Definition: vector.cpp:315
double dot_cv(cvector a, cvector b)
Definition: vector.cpp:623
double cv_norm(cvector v)
Definition: vector.cpp:644
void from_json(const string &s)
Set class contents from JSON string.
Definition: vector.h:256
rvector rv_sadd(double a, rvector b)
Add scalar to each element of vector.
Definition: vector.cpp:283
Vector(cvector cv)
Definition: vector.h:704
double norm_cv(cvector v)
Definition: vector.cpp:699
rvector rv_cross(rvector a, rvector b)
Take cross product of two row vectors.
Definition: vector.cpp:363
double sep_q(quaternion q1, quaternion q2)
Angular separation between quaternions.
Definition: vector.cpp:988
double w
Definition: vector.h:715
Quaternion, scalar last, using imaginary elements.
Definition: vector.h:450
Vector unitzV(double scale)
Definition: vector.cpp:2089
qfirst(double tq0, double tq1, double tq2, double tq3)
Definition: vector.h:570
quaternion q_evaluate_poly(double x, vector< vector< double > > parms)
Evaluate quaternion polynomial.
Definition: mathlib.cpp:1307
quaternion q_change_around_rv(rvector around, double angle)
Create rotation quaternion from row vector axis and angle.
Definition: mathlib.cpp:128
cvector cv_mult(cvector a, cvector b)
Multiply two vectors.
Definition: vector.cpp:602
3 element cartesian vector
Definition: vector.h:107
cvector cv_sadd(double a, cvector b)
Add scalar to each element of vector.
Definition: vector.cpp:538
rvector drotate(quaternion q, rvector v)
Rotate a row vector using a quaternion.
Definition: mathlib.cpp:2261
quaternion(cvector td, double tw)
Definition: vector.h:410