30 #ifndef _MATH_VECTOR_H 31 #define _MATH_VECTOR_H 58 rvector(
double d0,
double d1,
double d2) {
69 vector<double> v_col = vector<double>(
col, col+
sizeof(
col)/
sizeof(col[0]));
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();
89 cerr<<
"ERROR: <"<<error<<
">"<<endl;
96 std::ostream& operator << (std::ostream& out, const vector<rvector>&
a);
125 void normalize(
double scale=1.);
129 cvector normalized(
double scale=1.);
130 double& operator[] (
const int index);
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();
158 cerr<<
"ERROR: <"<<error<<
">"<<endl;
177 svector(
double tphi,
double tlambda,
double tr) {
190 {
"lambda" , lambda },
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();
209 cerr<<
"ERROR: <"<<error<<
">"<<endl;
232 gvector(
double tlat,
double tlon,
double th) {
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();
264 cerr<<
"ERROR: <"<<error<<
">"<<endl;
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();
319 cerr<<
"ERROR = "<<error<<endl;
436 if(!parsed[
"w"].is_null()) w = parsed[
"w"].number_value();
438 cerr<<
"ERROR: <"<<error<<
">"<<endl;
458 qcomplex(
double ti,
double tj,
double tk,
double tr) {
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();
493 cerr<<
"ERROR: <"<<error<<
">"<<endl;
514 qlast(
double tq1,
double tq2,
double tq3,
double tq4) {
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();
549 cerr<<
"ERROR: <"<<error<<
">"<<endl;
570 qfirst(
double tq0,
double tq1,
double tq2,
double tq3) {
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();
605 cerr<<
"ERROR: <"<<error<<
">"<<endl;
656 void qrotate(
double ipos[3],
double rpos[3],
double angle,
double *opos);
680 explicit Vector(
double x0=0.,
double y0=0.,
double z0=0.,
double w0=0.)
728 Vector &normalize(
double size=1.);
729 Vector &clear(
double x0=0.,
double y0=0.,
double z0=0.,
double w0=0.);
731 double separation(
Vector b);
745 double &operator [] (
const int &index);
748 Vector &operator *=(
const double &scale);
752 Vector &operator /= (
const double &scale);
756 Vector operator - ()
const;
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();
792 cerr<<
"ERROR: <"<<error<<
">"<<endl;
813 namespace Quaternions {
819 explicit Quaternion(
double qx=0.,
double qy=0.,
double qz=0.,
double qw=0.) : Vector(qx, qy, qz, qw)
863 Quaternion &operator *= (
const double scale);
886 Vector
irotate(
const Vector &v);
887 Vector
drotate(
const Vector &v);
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();
917 cerr<<
"ERROR: <"<<error<<
">"<<endl;
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
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
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
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