This example shows the basic math features available with the VectorNav library.
To compile and run for an environment not listed here, you will need to add all of the *.c
files in the directory <root>/c/src
along with the file located at <root>/cpp/examples/math/main.cpp
to your project for compilation. You will also need to add <root>/cpp/include
to your include directories.
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
vec3f v1(1.0f, 2.0f, 3.0f);
vec4f v3(1.0f, 2.0f, 3.0f, 4.0f);
string v1Str = str(v1);
cout << "v1: " << v1Str << endl;
cout << "v2: " << v2 << endl;
cout << "v3: " << v3 << endl;
cout << "zero vector: " << vec3f::zero() << endl;
cout << "x-direction vector: " << vec3f::unitX() << endl;
std::cout << "va: " << va << std::endl;
std::cout << "vb: " << vb << std::endl;
cout << "va + vb = " << va + vb << endl;
cout << "va - vb = " << va - vb << endl;
cout << "2 * va = " << 2.f * va << endl;
cout << "va / 3 = " << va / 3.f << endl;
cout << "-va = " << -va << endl;
cout <<
"va magnitude = " << va.
mag() << endl;
cout <<
"va normalized = " << va.
norm() << endl;
cout << "va y-component: " << va.y << endl;
cout << "va z-component: " << va[2] << endl;
cout << "v4: " << v4 << endl;
cout << "v5: " << v5 << endl;
mat3f m1(1, 2, 3, 4, 5, 6, 7, 8, 9);
string m1Str = str(m1);
cout << "m1: " << m1Str << endl;
cout << "m2: " << m2 << endl;
cout << "one 3x3 matrix: " << mat3f::one() << endl;
cout << "identity 3x3 matrix: " << mat3f::identity() << endl;
mat3f ma(1, 2, 3, 4, 5, 6, 7, 8, 9);
cout << "ma + mb = " << ma + mb << endl;
cout << "ma - mb = " << ma - mb << endl;
cout << "2 * ma = " << 2.f * ma << endl;
cout << "ma / 3 = " << ma / 3.f << endl;
cout << "-ma = " << -ma << endl;
cout <<
"ma transpose = " << ma.
transpose() << endl;
cout << "0,0 element of ma: " << ma.e00 << endl;
cout << "0,1 element of ma: " << ma(0,1) << endl;
cout << "m4: " << m4 << endl;
cout << "m5: " << m5 << endl;
return 0;
}