1 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 // + This file is part of enGrid. +
5 // + Copyright 2008-2014 enGits GmbH +
7 // + enGrid is free software: you can redistribute it and/or modify +
8 // + it under the terms of the GNU General Public License as published by +
9 // + the Free Software Foundation, either version 3 of the License, or +
10 // + (at your option) any later version. +
12 // + enGrid is distributed in the hope that it will be useful, +
13 // + but WITHOUT ANY WARRANTY; without even the implied warranty of +
14 // + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +
15 // + GNU General Public License for more details. +
17 // + You should have received a copy of the GNU General Public License +
18 // + along with enGrid. If not, see <http://www.gnu.org/licenses/>. +
20 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
22 // MathVector<V>(const MathVector<V>&)
23 // -----------------------------------
25 inline MathVector
<V
>::MathVector(const MathVector
<V
>& vec
) : V()
27 for (uint_t i
= 0; i
< this->size(); ++i
) (*this)[i
] = vec
[i
];
30 // MathVector<V>(const ParseNode<L,O,R>&)
31 // --------------------------------------
33 template <class L
, class O
, class R
>
34 inline MathVector
<V
>::MathVector(const ParseNode
<L
,O
,R
> &expr
) : V()
36 for (uint_t i
= 0; i
< this->size(); ++i
) (*this)[i
] = expr
[i
];
39 // MathVector<V>(const value_type *v)
40 // ----------------------------------
42 inline MathVector
<V
>::MathVector(const value_type
*v
) : V()
44 for (uint_t i
= 0; i
< this->size(); ++i
) (*this)[i
] = v
[i
];
47 // MathVector<V>(const value_type v1, const value_type v2, const value_type v3, const value_type v4)
48 // ----------------------------------------------------------------------------
50 inline MathVector
<V
>::MathVector(const value_type v1
,
53 const value_type v4
) : V()
61 // MathVector<V>(const value_type v1, const value_type v2, const value_type v3)
62 // ----------------------------------------------------------------------------
64 inline MathVector
<V
>::MathVector(const value_type v1
,
66 const value_type v3
) : V()
73 // MathVector<V>(const value_type v1, const value_type v2)
74 // ----------------------------------------------------------------------------
76 inline MathVector
<V
>::MathVector(const value_type v1
,
77 const value_type v2
) : V()
86 inline MathVector
<V
> MathVector
<V
>::cross(const MathVector
<V
> &vec
) const
88 MathVector
<V
> new_vec
;
89 new_vec
[0] = (*this)[1]*vec
[2] - (*this)[2]*vec
[1];
90 new_vec
[1] = (*this)[2]*vec
[0] - (*this)[0]*vec
[2];
91 new_vec
[2] = (*this)[0]*vec
[1] - (*this)[1]*vec
[0];
95 // absolute value (||v||_2 in this case)
96 // -------------------------------------
98 inline typename MathVector
<V
>::scalar_t MathVector
<V
>::abs() const
101 for (uint_t i
= 0; i
< this->size(); ++i
) l
+= (*this)[i
]*(*this)[i
];
105 // absolute value squared ((||v||_2)^2 in this case)
106 // -------------------------------------------------
108 inline typename MathVector
<V
>::scalar_t MathVector
<V
>::abs2() const
111 for (uint_t i
= 0; i
< this->size(); ++i
) l
+= (*this)[i
]*(*this)[i
];
115 // absolute value (||v||_2 in this case)
116 // -------------------------------------
117 template <class L
, class O
, class R
>
118 inline typename ParseNode
<L
,O
,R
>::value_type ParseNode
<L
,O
,R
>::abs() const
120 value_type abs_value
= 0;
121 for (uint_t i
= 0; i
< this->size(); ++i
) abs_value
+= (*this)[i
]*(*this)[i
];
122 return sqrt(abs_value
);
125 template <class O
, class R
>
126 inline typename ParseNode
<double,O
,R
>::value_type ParseNode
<double,O
,R
>::abs() const
128 value_type abs_value
= 0;
129 for (uint_t i
= 0; i
< this->size(); ++i
) abs_value
+= (*this)[i
]*(*this)[i
];
130 return sqrt(abs_value
);
133 // absolute value squared ((||v||_2)^2 in this case)
134 // -------------------------------------------------
135 template <class L
, class O
, class R
>
136 inline typename ParseNode
<L
,O
,R
>::value_type ParseNode
<L
,O
,R
>::abs2() const
138 value_type abs_value
= 0;
139 for (uint_t i
= 0; i
< this->size(); ++i
) abs_value
+= (*this)[i
]*(*this)[i
];
143 template <class O
, class R
>
144 inline typename ParseNode
<double,O
,R
>::value_type ParseNode
<double,O
,R
>::abs2() const
146 value_type abs_value
= 0;
147 for (uint_t i
= 0; i
< this->size(); ++i
) abs_value
+= (*this)[i
]*(*this)[i
];
151 // norm the vector to a length of 1 (according to ||v||_2)
152 // -------------------------------------------------------
154 inline MathVector
<V
> MathVector
<V
>::normalise()
157 for (uint_t i
= 0; i
< this->size(); ++i
) (*this)[i
] /= l
;
161 // create a C-style array
162 // ----------------------
164 typename MathVector
<V
>::scalar_t
* MathVector
<V
>::c_array() const
166 scalar_t
*t
= new scalar_t
[this->size()];
167 for (uint_t i
= 0; i
< this->size(); ++i
) t
[i
] = (*this)[i
];