KASKADE 7 development version
geomtools.hh
Go to the documentation of this file.
1/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2/* */
3/* This file is part of the library KASKADE 7 */
4/* https://www.zib.de/research/projects/kaskade7-finite-element-toolbox */
5/* */
6/* Copyright (C) 2002-2011 Zuse Institute Berlin */
7/* */
8/* KASKADE 7 is distributed under the terms of the ZIB Academic License. */
9/* see $KASKADE/academic.txt */
10/* */
11/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
12
13#ifndef GEOMTOOLS_HH
14#define GEOMTOOLS_HH
15
16#include <dune/common/fvector.hh>
17
18#include "fem/fixdune.hh"
19
26namespace GeomTools{
27
29 template<class Scalar>
31 return vectorProduct(v1,v2);
32 }
33
35 template<class Scalar>
37 result[0] = v1[1]*v2[2] - v1[2]*v2[1];
38 result[1] = v1[2]*v2[0] - v1[0]*v2[2];
39 result[2] = v1[0]*v2[1] - v1[1]*v2[0];
40 }
41
43 /*
44 * \param Vector Type of the input vector
45 * \param vector vector to be normalized
46 */
47 template<class Vector>
48 inline Vector normalize(Vector &vector){
49 if(vector.two_norm() < 1e-16) return vector;
50 vector /= vector.two_norm();
51 return vector;
52 }
53
55 /*
56 * \param Vector Type of the input vector, must provide a method called "two_norm()" for normalization,
57 * a copy constructor and /= operator.
58 * \param vector vector to be normalized
59 * \result normalized copy of vector
60 */
61 template<class Vector>
62 inline Vector getNormalized(Vector const& vector){
63 if(vector.two_norm() < 1e-16) return vector;
64 Vector result(vector);
65 result /= result.two_norm();
66 return result;
67 }
68
70 /*
71 * It is assumed that the origin of the coordinate system lies in the plane (no translation of vec).
72 *
73 * \param Vector Type of the input vector, must provide standard vector space operations.
74 * \param vec vector to project, will be replaced by the projection
75 * \param planeNormal unit(!) normal vector of the plane
76 */
77 template<class Vector>
78 inline void projectOnPlane(Vector &vec, Vector const& planeNormal){
79 vec -= (vec*planeNormal)*planeNormal;
80 }
81
83 /*
84 * It is assumed that the origin of the coordinate system lies in the plane (no translation of vec).
85 *
86 * \param Vector Type of the input vector, must provide standard vector space operations.
87 * \param vec vector to project, will be replaced by the projection
88 * \param projectionUnitNormal unit(!) normal vector (projection direction)
89 */
90 template <class Vector>
91 inline void project(Vector &vec, Vector const& projectionUnitNormal)
92 {
93 vec -=(vec*projectionUnitNormal)*projectionUnitNormal;
94 }
95}
96
97
98#endif // GEOMTOOLS_HH
99
This file contains various utility functions that augment the basic functionality of Dune.
T vectorProduct(Dune::FieldVector< T, 2 > const &x, Dune::FieldVector< T, 2 > const &y)
vector product .
Definition: fixdune.hh:209
Dune::FieldVector< Scalar, 3 > crossProduct(Dune::FieldVector< Scalar, 3 > const &v1, Dune::FieldVector< Scalar, 3 > const &v2)
DEPRECATED: use vectorProduct instead.
Definition: geomtools.hh:30
void projectOnPlane(Vector &vec, Vector const &planeNormal)
Project Vector vec on plane given through planeNormal. No translation is performed.
Definition: geomtools.hh:78
Vector normalize(Vector &vector)
Normalize vector.
Definition: geomtools.hh:48
void project(Vector &vec, Vector const &projectionUnitNormal)
Project Vector vec on plane given through planeNormal. No translation is performed.
Definition: geomtools.hh:91
Vector getNormalized(Vector const &vector)
Normalize vector.
Definition: geomtools.hh:62
Dune::FieldVector< Scalar, dim > Vector