2
3
4
5
6
7
8
9
10
11
12
13
14
15
17
18
19
20
21#ifndef CARTESIAN_VECTOR_HPP
22#define CARTESIAN_VECTOR_HPP
38 template<
typename T,
unsigned int L>
45 CartesianVector<T, L>() :
Matrix<T, L, 1>() {};
48 CartesianVector<T, L>(T elements) :
Matrix<T, L, 1>(elements) {};
52 CartesianVector<T, L>(
const T(&initial)[L]);
59 CartesianVector<T, L>(
const std::array<T, L> &initial);
63 ~CartesianVector<T, L>() {}
76 int set(
const unsigned int &idx,
const T &value) {
return Matrix<T, L, 1>::set(idx, 0, value);}
82 int get(
const unsigned int &idx, T &result)
const {
return Matrix<T, L, 1>::get(idx, 0, result);}
88 T
get(
const unsigned int &idx)
const {
return Matrix<T, L, 1>::get(idx, 0);}
92 int norm(T &result)
const;
96 T
norm()
const {T tmp; norm(tmp);
return tmp;}
104 T
normSquared()
const {T tmp; normSquared(tmp);
return tmp;}
121 std::string
str()
const;
124 template <
typename T,
unsigned int L>
133 for(i = 0; i < L; i++) {
134 Matrix<T, L, 1>::values[i][0] = initial[i];
138 template <
typename T,
unsigned int L>
139 CartesianVector<T, L>::CartesianVector(
const std::array<T, L> &initial) {
141 for(i = 0; i < L; i++) {
142 Matrix<T, L, 1>::values[i][0] = initial[i];
146 template <
typename T,
unsigned int L>
148 :
Matrix<T, L, 1>::Matrix(initial) {}
150 template <
typename T,
unsigned int L>
152 return Matrix<T, L, 1>::values[idx][0];
155 template <
typename T,
unsigned int L>
160 for(i = 0; i < L; i++) {
161 result +=
Matrix<T, L, 1>::values[i][0]*
Matrix<T, L, 1>::values[i][0];
165 int err = safeSqrt(result, result);
170 template <
typename T,
unsigned int L>
175 for(i = 0; i < L; i++) {
176 result +=
Matrix<T, L, 1>::values[i][0]*
Matrix<T, L, 1>::values[i][0];
182 template <
typename T,
unsigned int L>
194 for(i = 0; i < L; i++) {
195 result.values[i][0] =
Matrix<T, L, 1>::values[i][0]/mag;
200 template <
typename T,
unsigned int L>
210 template <
typename T,
unsigned int L>
215 template <
typename T,
unsigned int L>
217 std::string out =
"[";
219 for(
unsigned int i = 0; i < L; i++) {
223 out += std::to_string(
Matrix<T, L, 1>::values[i][0]);
Standard vector class derived from Matrix.
Definition CartesianVector.hpp:39
T & operator[](unsigned int idx)
Function to return a vector value.
Definition CartesianVector.hpp:151
int unit(CartesianVector< T, L > &result) const
Function to return the unitized version of the vector.
Definition CartesianVector.hpp:183
T norm() const
Function to take the norm of a vector.
Definition CartesianVector.hpp:96
int norm(T &result) const
Function to take the norm of a vector.
Definition CartesianVector.hpp:156
T normSquared() const
Function to take the squared norm of a vector.
Definition CartesianVector.hpp:104
int normalize()
Function to unitize the current vector.
Definition CartesianVector.hpp:211
T get(const unsigned int &idx) const
Getter specific to the vector class.
Definition CartesianVector.hpp:88
int unitize()
Function to unitize the current vector.
Definition CartesianVector.hpp:201
int get(const unsigned int &idx, T &result) const
Getter specific to the vector class.
Definition CartesianVector.hpp:82
int set(const unsigned int &idx, const T &value)
Setter specific to the vector class.
Definition CartesianVector.hpp:76
int normSquared(T &result) const
Function to take the squared norm of a vector.
Definition CartesianVector.hpp:171
std::string str() const
Function to write out vector as a string.
Definition CartesianVector.hpp:216
Matrix math implementation.
Definition Matrix.hpp:54
#define NO_ERROR
Definition clockwerkerrors.h:31
#define ERROR_DIVIDE_BY_ZERO
Definition clockwerkerrors.h:46