Kindfield
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Enumerations
Enumerator
Properties
Friends
Pages
src
math
vector3.h
Go to the documentation of this file.
1
#ifndef VECTOR3D_H
2
#define VECTOR3D_H
3
4
#include <iostream>
5
//#include <boost/serialization/serialization.hpp>
6
//#include <boost/mpi.hpp>
7
#include <armadillo>
8
9
class
Vector3
10
{
11
protected
:
12
double
mem_local
[3];
13
public
:
14
Vector3
();
15
Vector3
(
double
x
,
double
y
,
double
z
);
16
Vector3
(arma::rowvec armaVector);
17
18
// Operations
19
void
zeros
();
20
21
// Accessors
22
double
x
()
const
;
23
double
y
()
const
;
24
double
z
()
const
;
25
26
uint
size
()
const
;
27
28
// Operator overloading
29
double
&
operator()
(
const
int
component);
30
double
&
operator[]
(
const
int
component);
31
double
operator()
(
const
int
component)
const
;
32
double
operator[]
(
const
int
component)
const
;
33
friend
std::ostream&
operator<<
(std::ostream &out,
const
Vector3
&vector);
34
friend
Vector3
operator+
(
const
Vector3
&vector1,
const
Vector3
&vector2);
35
friend
Vector3
operator-
(
const
Vector3
&vector1,
const
Vector3
&vector2);
36
friend
Vector3
operator+
(
const
Vector3
&vector1);
37
friend
Vector3
operator-
(
const
Vector3
&vector1);
38
Vector3
&
operator=
(
const
Vector3
&vector2);
39
Vector3
&
operator+=
(
const
Vector3
&vector2);
40
Vector3
&
operator-=
(
const
Vector3
&vector2);
41
friend
Vector3
operator*
(
const
Vector3
&vector1,
const
Vector3
&vector2);
42
friend
bool
operator==
(
const
Vector3
&vector1,
const
Vector3
&vector2);
43
friend
bool
operator!=
(
const
Vector3
&vector1,
const
Vector3
&vector2);
44
45
// Operators with doubles
46
friend
Vector3
operator*
(
const
Vector3
&vector1,
double
value);
47
friend
Vector3
operator*
(
double
value,
const
Vector3
&vector1);
48
friend
Vector3
operator/
(
const
Vector3
&vector1,
double
value);
49
Vector3
&
operator*=
(
double
value);
50
Vector3
&
operator/=
(
double
value);
51
52
// Statics
53
static
Vector3
ones
();
54
static
Vector3
createZeros
();
55
56
static
double
dot
(
const
Vector3
&vector1,
const
Vector3
&vector2);
57
//private:
58
// friend class boost::serialization::access;
59
// template<class Archive>
60
// void serialize(Archive & ar, const unsigned int version);
61
};
62
63
inline
double
dot
(
const
Vector3
&vector1,
const
Vector3
&vector2) {
64
return
Vector3::dot
(vector1, vector2);
65
}
66
67
//BOOST_CLASS_IMPLEMENTATION(Vector3,object_serializable)
68
//BOOST_IS_BITWISE_SERIALIZABLE(Vector3)
69
//BOOST_IS_MPI_DATATYPE(Vector3)
70
//BOOST_CLASS_TRACKING(Vector3,track_never)
71
72
inline
Vector3::Vector3
()
73
{
74
mem_local
[0] = 0;
75
mem_local
[1] = 0;
76
mem_local
[2] = 0;
77
}
78
79
inline
Vector3::Vector3
(
double
x,
double
y,
double
z)
80
{
81
mem_local
[0] =
x
;
82
mem_local
[1] =
y
;
83
mem_local
[2] =
z
;
84
}
85
86
inline
Vector3::Vector3
(arma::rowvec armaVector)
87
{
88
mem_local
[0] = armaVector(0);
89
mem_local
[1] = armaVector(1);
90
mem_local
[2] = armaVector(2);
91
}
92
93
//template<class Archive>
94
//inline void Vector3::serialize(Archive & ar, const unsigned int)
95
//{
96
// ar &mem_local[0];
97
// ar &mem_local[1];
98
// ar &mem_local[2];
99
//}
100
101
inline
double
&
Vector3::operator[]
(
const
int
component)
102
{
103
return
mem_local
[component];
104
}
105
106
inline
double
&
Vector3::operator()
(
const
int
component)
107
{
108
return
mem_local
[component];
109
}
110
111
112
inline
double
Vector3::operator[]
(
const
int
component)
const
113
{
114
return
mem_local
[component];
115
}
116
117
inline
double
Vector3::operator()
(
const
int
component)
const
118
{
119
return
mem_local
[component];
120
}
121
122
inline
void
Vector3::zeros
() {
123
mem_local
[0] = 0;
124
mem_local
[1] = 0;
125
mem_local
[2] = 0;
126
}
127
128
inline
uint
Vector3::size
()
const
{
129
return
3;
130
}
131
132
133
inline
Vector3
operator+
(
const
Vector3
&vector1,
const
Vector3
&vector2)
134
{
135
return
Vector3
(vector1.
mem_local
[0] + vector2.
mem_local
[0], vector1.
mem_local
[1] + vector2.
mem_local
[1], vector1.
mem_local
[2] + vector2.
mem_local
[2]);
136
}
137
138
inline
Vector3
operator-
(
const
Vector3
&vector1,
const
Vector3
&vector2)
139
{
140
return
Vector3
(vector1.
mem_local
[0] - vector2.
mem_local
[0], vector1.
mem_local
[1] - vector2.
mem_local
[1], vector1.
mem_local
[2] - vector2.
mem_local
[2]);
141
}
142
143
inline
Vector3
&
Vector3::operator=
(
const
Vector3
&vector2)
144
{
145
this->
mem_local
[0] = vector2.
mem_local
[0];
146
this->
mem_local
[1] = vector2.
mem_local
[1];
147
this->
mem_local
[2] = vector2.
mem_local
[2];
148
return
*
this
;
149
}
150
151
inline
Vector3
&
Vector3::operator+=
(
const
Vector3
&vector2)
152
{
153
this->
mem_local
[0] += vector2.
mem_local
[0];
154
this->
mem_local
[1] += vector2.
mem_local
[1];
155
this->
mem_local
[2] += vector2.
mem_local
[2];
156
return
*
this
;
157
}
158
159
inline
Vector3
&
Vector3::operator*=
(
double
value)
160
{
161
this->
mem_local
[0] *= value;
162
this->
mem_local
[1] *= value;
163
this->
mem_local
[2] *= value;
164
return
*
this
;
165
}
166
167
inline
Vector3
&
Vector3::operator/=
(
double
value)
168
{
169
this->
mem_local
[0] /= value;
170
this->
mem_local
[1] /= value;
171
this->
mem_local
[2] /= value;
172
return
*
this
;
173
}
174
175
inline
Vector3
operator*
(
const
Vector3
&vector1,
double
value)
176
{
177
return
Vector3
(vector1.
mem_local
[0]*value, vector1.
mem_local
[1]*value, vector1.
mem_local
[2]*value);
178
}
179
180
inline
Vector3
operator*
(
double
value,
const
Vector3
&vector1)
181
{
182
return
Vector3
(vector1.
mem_local
[0]*value, vector1.
mem_local
[1]*value, vector1.
mem_local
[2]*value);
183
}
184
185
inline
Vector3
operator/
(
const
Vector3
&vector1,
double
value)
186
{
187
return
Vector3
(vector1.
mem_local
[0]/value, vector1.
mem_local
[1]/value, vector1.
mem_local
[2]/value);
188
}
189
190
inline
Vector3
&
Vector3::operator-=
(
const
Vector3
&vector2)
191
{
192
this->
mem_local
[0] -= vector2.
mem_local
[0];
193
this->
mem_local
[1] -= vector2.
mem_local
[1];
194
this->
mem_local
[2] -= vector2.
mem_local
[2];
195
return
*
this
;
196
}
197
198
inline
Vector3
operator+
(
const
Vector3
&vector1)
199
{
200
return
Vector3
(vector1.
mem_local
[0], vector1.
mem_local
[1], vector1.
mem_local
[2]);
201
}
202
203
inline
Vector3
operator-
(
const
Vector3
&vector1)
204
{
205
return
Vector3
(-vector1.
mem_local
[0], -vector1.
mem_local
[1], -vector1.
mem_local
[2]);
206
}
207
214
inline
Vector3
operator*
(
const
Vector3
&vector1,
const
Vector3
&vector2)
215
{
216
return
Vector3
(vector1.
mem_local
[0] * vector2.
mem_local
[0], vector1.
mem_local
[1] * vector2.
mem_local
[1], vector1.
mem_local
[2] * vector2.
mem_local
[2]);
217
}
218
219
inline
double
Vector3::dot
(
const
Vector3
&vector1,
const
Vector3
&vector2) {
220
return
(vector1.
mem_local
[0] * vector2.
mem_local
[0] + vector1.
mem_local
[1] * vector2.
mem_local
[1] + vector1.
mem_local
[2] * vector2.
mem_local
[2]);
221
}
222
223
224
inline
bool
operator==
(
const
Vector3
&vector1,
const
Vector3
&vector2)
225
{
226
return
((vector1.
mem_local
[0] == vector2.
mem_local
[0]) &&
227
(vector1.
mem_local
[1] == vector2.
mem_local
[1]) &&
228
(vector1.
mem_local
[2] == vector2.
mem_local
[2]));
229
}
230
231
inline
bool
operator !=
(
const
Vector3
&vector1,
const
Vector3
&vector2)
232
{
233
return
!(vector1 == vector2);
234
}
235
236
inline
double
Vector3::x
()
const
{
237
return
mem_local
[0];
238
}
239
inline
double
Vector3::y
()
const
{
240
return
mem_local
[1];
241
}
242
inline
double
Vector3::z
()
const
{
243
return
mem_local
[2];
244
}
245
246
#endif // VECTOR3D_H
Generated on Sun Jun 22 2014 14:02:46 for Kindfield by
1.8.4