From 5b63350b4a6e296fc242c3f7a0a913da8282fdf3 Mon Sep 17 00:00:00 2001 From: Oliver Sander <sander@igpm.rwth-aachen.de> Date: Mon, 9 Dec 2013 15:44:46 +0000 Subject: [PATCH] Revert patch 9558 We normalize unit vectors again in the constructor and the assignment operator. This makes sure we never drift away from the unit sphere, and it also allows us to init unit spheres with any value in R^n and be sure we obtain a unit vector. This makes the test pass again. Leaving the projection out didn't really make a measurable difference anyway. [[Imported from SVN: r9574]] --- dune/gfe/rotation.hh | 6 +++++- dune/gfe/unitvector.hh | 10 +++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/dune/gfe/rotation.hh b/dune/gfe/rotation.hh index 78494e84..24536405 100644 --- a/dune/gfe/rotation.hh +++ b/dune/gfe/rotation.hh @@ -196,11 +196,15 @@ public: { for (int i=0; i<4; i++) (*this)[i] = c[i]; + + *this /= this->two_norm(); } explicit Rotation<T,3>(const Dune::FieldVector<T,4>& c) : Quaternion<T>(c) - {} + { + *this /= this->two_norm(); + } Rotation<T,3>(Dune::FieldVector<T,3> axis, T angle) { diff --git a/dune/gfe/unitvector.hh b/dune/gfe/unitvector.hh index 3e3bf8ef..a218ee40 100644 --- a/dune/gfe/unitvector.hh +++ b/dune/gfe/unitvector.hh @@ -89,16 +89,19 @@ public: UnitVector() {} - /** \brief Constructor from a vector. The vector does not get normalized! */ + /** \brief Constructor from a vector. The vector gets normalized! */ UnitVector(const Dune::FieldVector<T,N>& vector) : data_(vector) - {} + { + data_ /= data_.two_norm(); + } - /** \brief Constructor from an array. The array does not get normalized! */ + /** \brief Constructor from an array. The array gets normalized! */ UnitVector(const Dune::array<T,N>& vector) { for (int i=0; i<N; i++) data_[i] = vector[i]; + data_ /= data_.two_norm(); } /** \brief Assigment from UnitVector with different type -- used for automatic differentiation with ADOL-C */ @@ -121,6 +124,7 @@ public: UnitVector<T,N>& operator=(const Dune::FieldVector<T,N>& vector) { data_ = vector; + data_ /= data_.two_norm(); return *this; } -- GitLab