2 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 // + This file is part of enGrid. +
6 // + Copyright 2008-2013 enGits GmbH +
8 // + enGrid is free software: you can redistribute it and/or modify +
9 // + it under the terms of the GNU General Public License as published by +
10 // + the Free Software Foundation, either version 3 of the License, or +
11 // + (at your option) any later version. +
13 // + enGrid is distributed in the hope that it will be useful, +
14 // + but WITHOUT ANY WARRANTY; without even the implied warranty of +
15 // + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +
16 // + GNU General Public License for more details. +
18 // + You should have received a copy of the GNU General Public License +
19 // + along with enGrid. If not, see <http://www.gnu.org/licenses/>. +
21 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
24 // MathVector<V>(const MathVector<V>&)
25 // -----------------------------------
27 inline MathVector
<V
>::MathVector(const MathVector
<V
>& vec
) : V()
29 for (uint_t i
= 0; i
< this->size(); ++i
) (*this)[i
] = vec
[i
];
32 // MathVector<V>(const ParseNode<L,O,R>&)
33 // --------------------------------------
35 template <class L
, class O
, class R
>
36 inline MathVector
<V
>::MathVector(const ParseNode
<L
,O
,R
> &expr
) : V()
38 for (uint_t i
= 0; i
< this->size(); ++i
) (*this)[i
] = expr
[i
];
41 // MathVector<V>(const value_type *v)
42 // ----------------------------------
44 inline MathVector
<V
>::MathVector(const value_type
*v
) : V()
46 for (uint_t i
= 0; i
< this->size(); ++i
) (*this)[i
] = v
[i
];
49 // MathVector<V>(const value_type v1, const value_type v2, const value_type v3, const value_type v4)
50 // ----------------------------------------------------------------------------
52 inline MathVector
<V
>::MathVector(const value_type v1
,
55 const value_type v4
) : V()
63 // MathVector<V>(const value_type v1, const value_type v2, const value_type v3)
64 // ----------------------------------------------------------------------------
66 inline MathVector
<V
>::MathVector(const value_type v1
,
68 const value_type v3
) : V()
75 // MathVector<V>(const value_type v1, const value_type v2)
76 // ----------------------------------------------------------------------------
78 inline MathVector
<V
>::MathVector(const value_type v1
,
79 const value_type v2
) : V()
88 inline MathVector
<V
> MathVector
<V
>::cross(const MathVector
<V
> &vec
) const
90 MathVector
<V
> new_vec
;
91 new_vec
[0] = (*this)[1]*vec
[2] - (*this)[2]*vec
[1];
92 new_vec
[1] = (*this)[2]*vec
[0] - (*this)[0]*vec
[2];
93 new_vec
[2] = (*this)[0]*vec
[1] - (*this)[1]*vec
[0];
97 // absolute value (||v||_2 in this case)
98 // -------------------------------------
100 inline typename MathVector
<V
>::scalar_t MathVector
<V
>::abs() const
103 for (uint_t i
= 0; i
< this->size(); ++i
) l
+= (*this)[i
]*(*this)[i
];
107 // absolute value squared ((||v||_2)^2 in this case)
108 // -------------------------------------------------
110 inline typename MathVector
<V
>::scalar_t MathVector
<V
>::abs2() const
113 for (uint_t i
= 0; i
< this->size(); ++i
) l
+= (*this)[i
]*(*this)[i
];
117 // absolute value (||v||_2 in this case)
118 // -------------------------------------
119 template <class L
, class O
, class R
>
120 inline typename ParseNode
<L
,O
,R
>::value_type ParseNode
<L
,O
,R
>::abs() const
122 value_type abs_value
= 0;
123 for (uint_t i
= 0; i
< this->size(); ++i
) abs_value
+= (*this)[i
]*(*this)[i
];
124 return sqrt(abs_value
);
127 template <class O
, class R
>
128 inline typename ParseNode
<double,O
,R
>::value_type ParseNode
<double,O
,R
>::abs() const
130 value_type abs_value
= 0;
131 for (uint_t i
= 0; i
< this->size(); ++i
) abs_value
+= (*this)[i
]*(*this)[i
];
132 return sqrt(abs_value
);
135 // absolute value squared ((||v||_2)^2 in this case)
136 // -------------------------------------------------
137 template <class L
, class O
, class R
>
138 inline typename ParseNode
<L
,O
,R
>::value_type ParseNode
<L
,O
,R
>::abs2() const
140 value_type abs_value
= 0;
141 for (uint_t i
= 0; i
< this->size(); ++i
) abs_value
+= (*this)[i
]*(*this)[i
];
145 template <class O
, class R
>
146 inline typename ParseNode
<double,O
,R
>::value_type ParseNode
<double,O
,R
>::abs2() const
148 value_type abs_value
= 0;
149 for (uint_t i
= 0; i
< this->size(); ++i
) abs_value
+= (*this)[i
]*(*this)[i
];
153 // norm the vector to a length of 1 (according to ||v||_2)
154 // -------------------------------------------------------
156 inline MathVector
<V
> MathVector
<V
>::normalise()
159 for (uint_t i
= 0; i
< this->size(); ++i
) (*this)[i
] /= l
;
163 // create a C-style array
164 // ----------------------
166 typename MathVector
<V
>::scalar_t
* MathVector
<V
>::c_array() const
168 scalar_t
*t
= new scalar_t
[this->size()];
169 for (uint_t i
= 0; i
< this->size(); ++i
) t
[i
] = (*this)[i
];