43 #ifndef __H__COMMON__VECTOR_FUNCTIONS_COMMON_IMPL__
44 #define __H__COMMON__VECTOR_FUNCTIONS_COMMON_IMPL__
55 template <
typename vector_target_t,
typename vector_source_t>
61 for(
size_t i = 0; i < minSize; ++i)
64 for(
size_t i = minSize; i <
target.size(); ++i)
69 template <
typename vector_t>
74 typedef typename vector_t::size_type size_type;
75 for(size_type i = 0; i < vOut.size(); ++i)
82 template <
typename vector_t>
85 VecAppend(vector_t& vOut,
const vector_t& v1,
const vector_t& v2)
87 typedef typename vector_t::size_type size_type;
88 for(size_type i = 0; i < vOut.size(); ++i)
90 vOut[i] += v1[i] + v2[i];
95 template <
typename vector_t>
98 VecAppend(vector_t& vOut,
const vector_t& v1,
const vector_t& v2,
101 typedef typename vector_t::size_type size_type;
102 for(size_type i = 0; i < vOut.size(); ++i)
104 vOut[i] += v1[i] + v2[i] + v3[i];
109 template <
typename vector_t>
112 VecAppend(vector_t& vOut,
const vector_t& v1,
const vector_t& v2,
113 const vector_t& v3,
const vector_t& v4)
115 typedef typename vector_t::size_type size_type;
116 for(size_type i = 0; i < vOut.size(); ++i)
118 vOut[i] += v1[i] + v2[i] + v3[i] + v4[i];
123 template <
typename vector_t>
128 typedef typename vector_t::size_type size_type;
129 for(size_type i = 0; i < vOut.size(); ++i)
131 vOut[i] += s1 * v1[i];
136 template <
typename vector_t>
142 typedef typename vector_t::size_type size_type;
143 for(size_type i = 0; i < vOut.size(); ++i)
145 vOut[i] += s1 * v1[i] + s2 * v2[i];
150 template <
typename vector_t>
157 typedef typename vector_t::size_type size_type;
158 for(size_type i = 0; i < vOut.size(); ++i)
160 vOut[i] += s1 * v1[i] + s2 * v2[i] + s3 * v3[i];
165 template <
typename vector_t>
173 typedef typename vector_t::size_type size_type;
174 for(size_type i = 0; i < vOut.size(); ++i)
176 vOut[i] += s1 * v1[i] + s2 * v2[i] + s3 * v3[i] + s4 * v4[i];
182 template <
typename vector_t>
185 VecAdd(vector_t& vOut,
const vector_t& v1,
const vector_t& v2)
187 typedef typename vector_t::size_type size_type;
188 for(size_type i = 0; i < vOut.size(); ++i)
190 vOut[i] = v1[i] + v2[i];
195 template <
typename vector_t>
198 VecAdd(vector_t& vOut,
const vector_t& v1,
const vector_t& v2,
201 typedef typename vector_t::size_type size_type;
202 for(size_type i = 0; i < vOut.size(); ++i)
204 vOut[i] = v1[i] + v2[i] + v3[i];
209 template <
typename vector_t>
212 VecAdd(vector_t& vOut,
const vector_t& v1,
const vector_t& v2,
213 const vector_t& v3,
const vector_t& v4)
215 typedef typename vector_t::size_type size_type;
216 for(size_type i = 0; i < vOut.size(); ++i)
218 vOut[i] = v1[i] + v2[i] + v3[i] + v4[i];
223 template <
typename vector_t>
226 VecSubtract(vector_t& vOut,
const vector_t& v1,
const vector_t& v2)
228 typedef typename vector_t::size_type size_type;
229 for(size_type i = 0; i < vOut.size(); ++i)
231 vOut[i] = v1[i] - v2[i];
236 template <
typename vector_t>
241 typedef typename vector_t::size_type size_type;
242 for(size_type i = 0; i < vOut.size(); ++i)
244 vOut[i] = std::pow(v1[i],
s);
249 template <
typename vector_t>
254 typedef typename vector_t::size_type size_type;
255 for(size_type i = 0; i < vOut.size(); ++i)
262 template <
typename vector_t>
268 typedef typename vector_t::size_type size_type;
269 for(size_type i = 0; i < vOut.size(); ++i)
271 vOut[i] = s1 * v1[i] + s2 * v2[i];
276 template <
typename vector_t>
283 typedef typename vector_t::size_type size_type;
284 for(size_type i = 0; i < vOut.size(); ++i)
286 vOut[i] = s1 * v1[i] + s2 * v2[i] + s3 * v3[i];
291 template <
typename vector_t>
299 typedef typename vector_t::size_type size_type;
300 for(size_type i = 0; i < vOut.size(); ++i)
302 vOut[i] = s1 * v1[i] + s2 * v2[i] + s3 * v3[i] + s4 * v4[i];
307 template <
typename vector_t>
313 typedef typename vector_t::size_type size_type;
314 for(size_type i = 0; i < vOut.size(); ++i)
316 vOut[i] = (1. - interpAmount) * v1[i] + interpAmount * v2[i];
321 template <
typename vector_t>
327 typedef typename vector_t::size_type size_type;
329 for(size_type i = 0; i < v.size(); ++i)
338 template <
typename vector_t>
348 template <
typename vector_t>
359 template <
typename TVector,
typename TMatrix>
368 return VecDot(deltaM, delta);
372 template <
typename vector_t>
382 template <
typename vector_t>
385 VecDot(
const vector_t& v1,
const vector_t& v2)
388 typedef typename vector_t::size_type size_type;
390 for(size_type i = 0; i < v1.size(); ++i)
398 template <
typename vector_t>
418 template <
typename vector_t>
434 template <
typename vector_t>
437 VecCross(vector_t& vOut,
const vector_t& v1,
const vector_t& v2)
439 if(&vOut != &v1 && &vOut != &v2)
441 vOut[0] = v1[1] * v2[2] - v2[1] * v1[2];
442 vOut[1] = v1[2] * v2[0] - v2[2] * v1[0];
443 vOut[2] = v1[0] * v2[1] - v2[0] * v1[1];
448 _temp[0] = v1[1] * v2[2] - v2[1] * v1[2];
449 _temp[1] = v1[2] * v2[0] - v2[2] * v1[0];
450 _temp[2] = v1[0] * v2[1] - v2[0] * v1[1];
463 template <
size_t dim>
471 UG_THROW (
"The generalized vector product is defined only in 2 and 3 dimensions");
482 result[0] = v_1[0] * v_2[1] - v_1[1] * v_2[0];
498 template <
typename vector_t>
511 template <
typename vector_t>
515 const vector_t& v2,
const vector_t& v3)
525 template <
typename vector_t>
529 const vector_t& v2,
const vector_t& v3)
536 template <
typename vector_t>
541 typedef typename vector_t::size_type size_type;
542 for(size_type i = 0; i < vInOut.size(); ++i)
549 template <
typename vector_t>
554 typedef typename vector_t::size_type size_type;
555 for(size_type i = 0; i < vOut.size(); ++i)
562 template <
typename vector_t>
567 typedef typename vector_t::size_type size_type;
568 for(size_type i = 0; i < vOut.size(); ++i)
574 template <
typename vector_t>
582 template <
typename vector_t>
590 template <
typename vector_t>
596 typedef typename vector_t::size_type size_type;
598 for(size_type i = 0; i < v.size(); ++i)
600 len += std::abs(v[i]);
606 template <
typename vector_t>
612 typedef typename vector_t::size_type size_type;
614 for(size_type i = 0; i < v.size(); ++i)
616 len += std::pow(v[i],
p);
622 template <
typename vector_t>
628 typedef typename vector_t::size_type size_type;
630 for(size_type i = 0; i < v.size(); ++i)
632 m = std::max(m, v[i]);
638 template <
typename vector_t>
648 template <
typename vector_t>
651 VecElemProd(vector_t& vOut,
const vector_t& v1,
const vector_t& v2)
653 typedef typename vector_t::size_type size_type;
654 for(size_type i = 0; i < vOut.size(); ++i)
656 vOut[i] = v1[i] * v2[i];
661 template <
typename vector_t>
666 typedef typename vector_t::size_type size_type;
667 for(size_type i = 0; i < vOut.size(); ++i)
669 vOut[i] = sqrt(v1[i]);
674 template <
typename vector_t>
679 for(
typename vector_t::size_type i = 0; i < v1.size(); ++i)
680 if (std::abs (v1[i]) >= std::abs (v2[i]))
686 template <
typename vector_t>
691 for(
typename vector_t::size_type i = 0; i < v1.size(); ++i)
692 if (std::abs (v1[i]) >=
s)
698 template <
typename vector_t>
701 VecIsInBB(
const vector_t& v,
const vector_t& low,
const vector_t& high)
703 for(
typename vector_t::size_type i = 0; i < v.size(); ++i)
704 if (v[i] < low[i] || high[i] < v[i])
#define UG_THROW(msg)
Definition: error.h:57
double number
Definition: types.h:124
void MatVecMult(vector_t_out &vOut, const matrix_t &m, const vector_t_in &v)
Matrix - Vector Multiplication.
Definition: math_matrix_vector_functions_common_impl.hpp:49
vector_t::value_type VecLength(const vector_t &v)
returns the length of v. Slower than VecLengthSq.
Definition: math_vector_functions_common_impl.hpp:341
void VecScaleAppend(vector_t &vOut, typename vector_t::value_type s1, const vector_t &v1)
Scales a Vector and adds it to a second vector.
Definition: math_vector_functions_common_impl.hpp:126
void VecCopy(vector_target_t &target, const vector_source_t &source, typename vector_target_t::value_type fill)
Copy contents between vectors of possibly different types.
Definition: math_vector_functions_common_impl.hpp:56
vector_t::value_type VecMaxNorm(const vector_t &v)
Definition: math_vector_functions_common_impl.hpp:625
void GenVecCross(MathVector< dim > &result, const MathVector< dim > &v_1, const MathVector< dim > &v_2)
calculates the usual cross product in 3d, and the (det, 0) vector as a cross product in 2d
Definition: math_vector_functions_common_impl.hpp:465
void VecSet(vector_t &vInOut, typename vector_t::value_type s)
Set each vector component to scalar (componentwise)
Definition: math_vector_functions_common_impl.hpp:539
void VecScaleAdd(vector_t &vOut, typename vector_t::value_type s1, const vector_t &v1, typename vector_t::value_type s2, const vector_t &v2)
Scales two Vectors, adds them and returns the sum in a third vector.
Definition: math_vector_functions_common_impl.hpp:265
vector_t::value_type VecTwoNormSq(const vector_t &v)
Definition: math_vector_functions_common_impl.hpp:585
vector_t::value_type VecOneNorm(const vector_t &v)
Definition: math_vector_functions_common_impl.hpp:593
void VecNormalize(vector_t &vOut, const vector_t &v)
scales a vector_t to unit length
Definition: math_vector_functions_common_impl.hpp:501
void CalculateTriangleNormalNoNormalize(vector_t &vOut, const vector_t &v1, const vector_t &v2, const vector_t &v3)
Calculates a triangle-normal in 3d (no normalization is performed).
Definition: math_vector_functions_common_impl.hpp:514
void VecSubtract(vector_t &vOut, const vector_t &v1, const vector_t &v2)
subtracts v2 from v1 and stores the result in a vOut
Definition: math_vector_functions_common_impl.hpp:226
vector_t::value_type VecAngle(const vector_t &v1, const vector_t &v2)
returns the angle between two vectors in radiants
Definition: math_vector_functions_common_impl.hpp:401
vector_t::value_type VecDistanceSq(const vector_t &v1, const vector_t &v2)
returns the squared distance of two vector_ts.
Definition: math_vector_functions_common_impl.hpp:351
void CalculateTriangleNormal(vector_t &vOut, const vector_t &v1, const vector_t &v2, const vector_t &v3)
Calculates a triangle-normal in 3d (output has length 1).
Definition: math_vector_functions_common_impl.hpp:528
void VecAppend(vector_t &vOut, const vector_t &v1)
adds a MathVector<N> to a second one
Definition: math_vector_functions_common_impl.hpp:72
vector_t::value_type VecLengthSq(const vector_t &v)
returns the squared length of v. Faster than VecLength.
Definition: math_vector_functions_common_impl.hpp:324
vector_t::value_type VecDistance(const vector_t &v1, const vector_t &v2)
returns the distance of two vector_ts.
Definition: math_vector_functions_common_impl.hpp:375
void VecAdd(vector_t &vOut, const vector_t &v1, const vector_t &v2)
adds two MathVector<N>s and stores the result in a third one
Definition: math_vector_functions_common_impl.hpp:185
void VecScale(vector_t &vOut, const vector_t &v, typename vector_t::value_type s)
scales a MathVector<N>
Definition: math_vector_functions_common_impl.hpp:252
vector_t::value_type VecTwoNorm(const vector_t &v)
Definition: math_vector_functions_common_impl.hpp:577
void VecCross(vector_t &vOut, const vector_t &v1, const vector_t &v2)
calculates the cross product of two Vectors of dimension 3. It makes no sense to use VecCross for vec...
Definition: math_vector_functions_common_impl.hpp:437
void VecPow(vector_t &vOut, const vector_t &v1, typename vector_t::value_type s)
component-wise exponentiation of a vector
Definition: math_vector_functions_common_impl.hpp:239
vector_t::value_type VecAngleNorm(const vector_t &v1, const vector_t &v2)
returns the angle between two vectors of length 1 in radiants
Definition: math_vector_functions_common_impl.hpp:421
void VecInterpolateLinear(vector_t &vOut, const vector_t &v1, const vector_t &v2, typename vector_t::value_type interpAmount)
Definition: math_vector_functions_common_impl.hpp:310
vector_t::value_type VecDot(const vector_t &v1, const vector_t &v2)
returns the dot-product of two vector_ts
Definition: math_vector_functions_common_impl.hpp:385
vector_t::value_type VecInftyNorm(const vector_t &v)
Definition: math_vector_functions_common_impl.hpp:641
vector_t::value_type VecPNorm(const vector_t &v, unsigned int p)
Definition: math_vector_functions_common_impl.hpp:609
size_t target(SM_edge< typename T::value_type > const &e, ug::BidirectionalMatrix< T > const &m)
Definition: bidirectional_boost.h:100
size_t source(SM_edge< typename T::value_type > const &e, ug::BidirectionalMatrix< T > const &)
Definition: bidirectional_boost.h:94
bool VecIsInBB(const vector_t &v, const vector_t &low, const vector_t &high)
checks if the given point is in the bounding box given by two other points
Definition: math_vector_functions_common_impl.hpp:701
const number PI
Definition: math_constants.h:45
void GenVecCross< 2 >(MathVector< 2 > &result, const MathVector< 2 > &v_1, const MathVector< 2 > &v_2)
specialization of the "generalized vector product" in 2d.
Definition: math_vector_functions_common_impl.hpp:477
void GenVecCross< 3 >(MathVector< 3 > &result, const MathVector< 3 > &v_1, const MathVector< 3 > &v_2)
specialization of the "generalized vector product" in 3d.
Definition: math_vector_functions_common_impl.hpp:489
void VecElemProd(vector_t &vOut, const vector_t &v1, const vector_t &v2)
component-wise product: vOut_i = v1_i*v2_i
Definition: math_vector_functions_common_impl.hpp:651
bool VecAbsIsLess(const vector_t &v1, const vector_t &v2)
component-wise comparison of two vectors (in the absolute values)
Definition: math_vector_functions_common_impl.hpp:677
void VecElemSqrt(vector_t &vOut, const vector_t &v1)
component-wise square root:
Definition: math_vector_functions_common_impl.hpp:664
T value_type
Definition: sparsematrix_interface.h:2