Go to the documentation of this file.00001 #ifndef OPENTISSUE_DYNAMICS_EDM_MODELS_EDM_ELLIPSOID_PATCH_H
00002 #define OPENTISSUE_DYNAMICS_EDM_MODELS_EDM_ELLIPSOID_PATCH_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/dynamics/edm/edm_surface.h>
00013 #include <OpenTissue/core/math/math_constants.h>
00014
00015 #include <cmath>
00016
00017
00018 namespace OpenTissue
00019 {
00020 namespace edm
00021 {
00022
00023 template<typename edm_types>
00024 class EllipsoidPatch
00025 : public Surface<edm_types>
00026 {
00027 public:
00028
00029 typedef Surface<edm_types> base_type;
00030 typedef typename edm_types::real_type real_type;
00031 typedef typename edm_types::vector3_type vector3_type;
00032
00033 public:
00034
00035 EllipsoidPatch()
00036 : base_type()
00037 {
00038 base_type::set(NUM_NODES);
00039 }
00040
00041 virtual ~EllipsoidPatch() {}
00042
00043 private:
00044
00045 vector3_type position(vector3_type const * a, real_type const & u, real_type const & v) const
00046 {
00047 real_type const u_ = u - u / this->m_M;
00048
00049 real_type const v_ = v == 0 ? 0.001 : v >= 1. ? 0.999 : v;
00050 real_type const theta = 2. * math::detail::pi<real_type>() * ( 1. - u_ );
00051 real_type const phi = math::detail::pi<real_type>() * v_;
00052
00053 vector3_type local = p( a[ 0 ][ 0 ], a[ 0 ][ 1 ], a[ 0 ][ 2 ], theta, phi );
00054
00055 return vector3_type(local + a[ 1 ]);
00056 }
00057
00058 vector3_type normal(size_t m, size_t n) const
00059 {
00060
00061
00062
00063 long lm = m;
00064 long ln = n;
00065
00066
00067 vector3_type const v = this->r( lm + 1, n ) - this->r( lm - 1, n );
00068 vector3_type const w = this->r( lm, n + 1 ) - this->r( lm, n - 1 );
00069 return vector3_type(
00070 unit( cross(v , w) )
00071 );
00072 }
00073
00074 private:
00075
00076 vector3_type p(real_type const & a, real_type const & b, real_type const & c, real_type const & theta, real_type const & phi) const
00077 {
00078 using std::cos;
00079 using std::sin;
00080 const real_type x = a * cos( theta ) * sin( phi );
00081 const real_type y = b * sin( theta ) * sin( phi );
00082 const real_type z = c * cos( phi );
00083 return vector3_type( x, y, z );
00084 }
00085
00086 private:
00087
00088 enum {NUM_NODES = 2};
00089
00090 };
00091
00092 }
00093
00094 }
00095
00096
00097 #endif