CellModules
basis.hpp
Go to the documentation of this file.
1#ifndef MECACELL_BASIS_H
2#define MECACELL_BASIS_H
3#include <iostream>
4#include "rotation.h"
5
6namespace MecaCell {
7template <typename V> struct Basis {
8 V X = V(1, 0, 0), Y = V(0, 1, 0);
9 Basis() {}
10 Basis(const V &x, const V &y) : X(x), Y(y) {}
11
12 V getZ() { return X.cross(Y).normalized(); }
13
15 X = V(1, 0, 0).rotated(r).normalized();
16 Y = V(0, 1, 0).rotated(r).normalized();
17 }
18
19 void rotate(const Rotation<V> &r) {
20 X = X.rotated(r);
21 Y = Y.rotated(r);
22 normalize();
23 }
24
25 void normalize() {
26 X.normalize();
27 Y.normalize();
28 }
29
31 return Basis(X.rotated(r).normalized(), Y.rotated(r).normalized());
32 }
33
34 template <typename T>
35 friend std::ostream &operator<<(std::ostream &out, const Basis<T> &b);
36};
37
38template <typename T> inline std::ostream &operator<<(std::ostream &out, const Basis<T> &b) {
39 out << "[ " << b.X << ", " << b.Y << ", "<<b.Z<<" ]";
40 return out;
41}
42}
43#endif
this file contains various miscellanious utility functions & helpers *
std::ostream & operator<<(std::ostream &out, const Basis< T > &b)
Definition: basis.hpp:38
void updateWithRotation(const Rotation< V > &r)
Definition: basis.hpp:14
friend std::ostream & operator<<(std::ostream &out, const Basis< T > &b)
Definition: basis.hpp:38
Basis(const V &x, const V &y)
Definition: basis.hpp:10
Basis rotated(const Rotation< V > &r)
Definition: basis.hpp:30
void rotate(const Rotation< V > &r)
Definition: basis.hpp:19
void normalize()
Definition: basis.hpp:25