Go to the documentation of this file.00001 #ifndef OPENTISSUE_COLLISION_GJK_GJK_SUPPORT_FUNCTORS_ELLIPSOID_H
00002 #define OPENTISSUE_COLLISION_GJK_GJK_SUPPORT_FUNCTORS_ELLIPSOID_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/core/math/math_is_number.h>
00013
00014 #include <cmath>
00015 #include <cassert>
00016
00017 namespace OpenTissue
00018 {
00019 namespace gjk
00020 {
00024 template<typename math_types>
00025 class Ellipsoid
00026 {
00027 protected:
00028
00029 typedef typename math_types::real_type T;
00030 typedef typename math_types::vector3_type V;
00031 typedef typename math_types::value_traits value_traits;
00032
00033 V m_scale;
00034
00035 public:
00036
00042 V const & scale() const { return this->m_scale; }
00043 V & scale() { return this->m_scale; }
00044
00045 public:
00046
00047 Ellipsoid()
00048 : m_scale( value_traits::one(), value_traits::one(), value_traits::one() )
00049 {}
00050
00051 public:
00052
00053 V operator()(V const & v) const
00054 {
00055 using std::sqrt;
00056
00057 assert( this->m_scale(0) >= value_traits::zero() || !"Ellipsoid::operator(): Negative scale encountered");
00058 assert( this->m_scale(1) >= value_traits::zero() || !"Ellipsoid::operator(): Negative scale encountered");
00059 assert( this->m_scale(2) >= value_traits::zero() || !"Ellipsoid::operator(): Negative scale encountered");
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082 T vv = dot(v,v);
00083 assert( is_number(vv) || !"Ellipsoid::operator(): NaN encountered");
00084
00085 if (vv > value_traits::zero() )
00086 {
00087 V const w = V(
00088 v(0) * (this->m_scale(0))
00089 , v(1) * (this->m_scale(1))
00090 , v(2) * (this->m_scale(2))
00091 );
00092 T const ww = dot(w,w);
00093 assert( is_number(ww) || !"Ellipsoid::operator(): NaN encountered");
00094
00095 T const tmp = value_traits::one() / sqrt(ww);
00096 assert( is_number(tmp) || !"Ellipsoid::operator(): NaN encountered");
00097
00098 V const s = V(
00099 w(0) * (tmp * (this->m_scale(0)))
00100 , w(1) * (tmp * (this->m_scale(1)))
00101 , w(2) * (tmp * (this->m_scale(2)))
00102 );
00103 assert( is_number( s(0) ) || !"Ellipsoid::operator(): NaN encountered");
00104 assert( is_number( s(1) ) || !"Ellipsoid::operator(): NaN encountered");
00105 assert( is_number( s(2) ) || !"Ellipsoid::operator(): NaN encountered");
00106
00107 return s;
00108 }
00109 return V( this->m_scale(0), value_traits::zero(), value_traits::zero() );
00110 }
00111
00112 };
00113
00114 }
00115
00116 }
00117
00118
00119 #endif