Go to the documentation of this file.00001 #ifndef OPENTISSUE_DYNAMICS_MBD_UTIL_SCRIPTED_MBD_OSCILLATION_H
00002 #define OPENTISSUE_DYNAMICS_MBD_UTIL_SCRIPTED_MBD_OSCILLATION_H
00003
00004
00005
00006
00007 #include <OpenTissue/configuration.h>
00008
00009 #include <OpenTissue/dynamics/mbd/interfaces/mbd_scripted_motion_interface.h>
00010
00011 namespace OpenTissue
00012 {
00013 namespace mbd
00014 {
00015
00034 template<typename mbd_types>
00035 class Oscillation
00036 : public ScriptedMotionInterface<mbd_types>
00037 {
00038 protected:
00039
00040 typedef typename mbd_types::body_type body_type;
00041 typedef typename mbd_types::math_policy math_policy;
00042 typedef typename math_policy::value_traits value_traits;
00043 typedef typename math_policy::real_type real_type;
00044 typedef typename math_policy::vector3_type vector3_type;
00045 typedef typename math_policy::quaternion_type quaternion_type;
00046
00047 protected:
00048
00049 vector3_type m_origin;
00050 vector3_type m_dir;
00051 real_type m_amplitude;
00052 real_type m_frequency;
00053 real_type m_phase;
00054
00055 public:
00056
00057 Oscillation()
00058 : m_origin(value_traits::zero(),value_traits::zero(),value_traits::zero())
00059 , m_dir(value_traits::one(),value_traits::zero(),value_traits::zero())
00060 , m_amplitude(10*value_traits::one())
00061 , m_frequency(2*value_traits::pi())
00062 , m_phase(value_traits::pi())
00063 {}
00064
00065 virtual ~Oscillation(){}
00066
00067 public:
00068
00085 void compute(body_type const & body,real_type const & time,vector3_type & r,quaternion_type & q, vector3_type & v,vector3_type & w)
00086 {
00087 using std::cos;
00088 using std::sin;
00089
00090 r = m_dir*m_amplitude*cos(m_frequency*time + m_phase) + m_origin;
00091 v = - m_dir*m_frequency*m_amplitude*sin(m_frequency*time + m_phase);
00092 q.identity();
00093 w.clear();
00094 }
00095
00096 public:
00097
00103 void set_origin(vector3_type const & origin){ m_origin = origin; }
00104
00110 void get_origin(vector3_type & origin) const { origin = m_origin; }
00111
00117 void set_direction(vector3_type const & dir) { m_dir = unit(dir); }
00118
00124 void get_direction(vector3_type & dir) const { dir = m_dir; }
00125
00126 void set_frequency(real_type const & frequency)
00127 {
00128 assert(frequency>=value_traits::zero() || !"Oscillation::set_frequency(): frequency must be non-negative");
00129 m_frequency = frequency;
00130 }
00131
00132 real_type get_frequency() const { return m_frequency; }
00133
00134 void set_phase(real_type const & phase) { m_phase = phase; }
00135
00136 real_type get_phase() const { return m_phase; }
00137
00138 void set_amplitude(real_type const & amplitude)
00139 {
00140 assert(amplitude>=value_traits::zero() || !"Oscillation::set_amplitude(): amplitude must be non-negative");
00141 m_amplitude = amplitude;
00142 }
00143
00144 real_type get_amplitude() const { return m_amplitude; }
00145
00146 };
00147
00148 }
00149 }
00150
00151 #endif