units
Use physical dimensions at compile-time or run-time.
Classes | Namespaces | Typedefs | Functions
example1.cpp File Reference
#include <array>
#include <eigen3/Eigen/Geometry>
#include <iostream>
#include <type_traits>
#include <utility>
#include <vnix/units.hpp>
Include dependency graph for example1.cpp:

Go to the source code of this file.

Classes

class  vnix::mv::mref< T, S, N >
 Reference to column or row in matrix. More...
 
struct  vnix::mv::mat< T, NR, NC >
 Model of a matrix of quantities. More...
 

Namespaces

 vnix
 Thomas E. Vaughan's public software.
 
 vnix::mv
 

Typedefs

template<typename T , size_t NR>
using vnix::mv::col = mat< T, NR, 1 >
 Model of column of quantities. More...
 
template<typename T , size_t NC>
using vnix::mv::row = mat< T, 1, NC >
 Model of row of quantities. More...
 

Functions

template<typename T , typename OT , size_t N>
constexpr T vnix::mv::cnv_el (array< OT, N > const &a, size_t i)
 Convert element i of array a from type OT to type T. More...
 
template<typename T , typename OT , size_t... i>
constexpr auto vnix::mv::_cnv (array< OT, sizeof...(i)> const &a, index_sequence< i... >)
 Convert array of elements of type OT to array of elements of type T. More...
 
template<typename T , typename OT , size_t N>
constexpr auto vnix::mv::cnv_ar (array< OT, N > const &a)
 Convert array of elements of type OT to array of elements of type T. More...
 
template<typename T1 , typename T2 , size_t S1, size_t S2, size_t N>
constexpr auto vnix::mv::dot (mref< T1, S1, N > const &mr1, mref< T2, S2, N > const &mr2)
 Dot-product of two mrefs. More...
 
template<typename T1 , typename T2 , size_t NR1, size_t NC2, size_t N>
constexpr auto vnix::mv::operator* (mat< T1, NR1, N > const &m1, mat< T2, N, NC2 > const &m2)
 Multiply two matrices. More...
 
template<typename T1 , typename T2 , size_t NR2, size_t NC2>
constexpr auto vnix::mv::operator* (T1 const &s1, mat< T2, NR2, NC2 > const &m2)
 Multiply matrix on left by scalar. More...
 
template<typename T , size_t NR, size_t NC>
ostream & vnix::mv::operator<< (ostream &os, mat< T, NR, NC > const &m)
 Print matrix. More...
 
int main ()
 

Function Documentation

int main ( )

Definition at line 171 of file example1.cpp.

171  {
172  try {
173  using namespace vnix::mv;
174  mat<float, 3, 3> m1;
175  m1.row(0) = {1, 2, 3};
176  m1.row(1) = {4, 5, 6};
177  m1.row(2) = {7, 8, 9};
178  col<double, 3> v({0.3, 0.2, 0.1});
179  auto f = vnix::units::newtons(m1);
180  auto d = vnix::units::kilometers(v);
181  cout << (f * d) << endl;
182  } catch (char const *e) { cerr << e << endl; }
183 
184  cout << endl;
185 
186  try {
187  using namespace vnix::mv;
188  using namespace vnix::units::flt;
189  force foo;
190  mat<force, 3, 3> f2;
191  f2.row(0) = {1.0_N, 2.0_N, 3.0_N};
192  f2.row(1) = {4.0_N, 5.0_N, 6.0_N};
193  f2.row(2) = {7.0_N, 8.0_N, 9.0_N};
194  col<length, 3> d2({0.3_km, 0.2_km, 0.1_km});
195  cout << (f2 * d2) << endl;
196  } catch (char const *e) { cerr << e << endl; }
197 
198  cout << endl;
199 
200  try {
201  using namespace Eigen;
202  using namespace vnix::units;
203  using namespace vnix::units::flt;
204  AngleAxisf r(M_PI / 6, Vector3f(0, 0, 1));
205  auto f = newtons(Vector3f(1, 0, 0));
206  auto d = meters(Vector3f(0, 1, 0));
207  auto v = d / (2.5_s);
208  flt::time t = 3.0_s;
209  cout << (r.toRotationMatrix() * f).cross(d + v * t) << endl;
210  } catch (char const *e) { cerr << e << endl; }
211 
212  return 0;
213 }
decltype(N/1) force
Definition: units.hpp:2208
Definition: number.hpp:11
constexpr auto kilometers(T v)
Produce dimensioned quantity from number of kilometers.
Definition: units.hpp:1359
Single-precision dimensions and units.
Definition: units.hpp:1663
constexpr auto meters(T v)
Produce dimensioned quantity from number of meters.
Definition: units.hpp:1317
Model of a matrix of quantities.
Definition: number.hpp:23
Model of a statically dimensioned physical quantity.
Definition: dimval.hpp:24
Classes and functions supporting a model of physically dimensioned quantities.
constexpr auto newtons(T v)
Produce dimensioned quantity from number of newtons.
Definition: units.hpp:1533

Here is the call graph for this function: