TAPs 0.7.7.3
TAPsSpringVertex.cpp
Go to the documentation of this file.
00001 /******************************************************************************
00002 TAPsSpringVertex.cpp
00003 
00004 SpringVertex class is a class for a spring connecting between two ParticleVertex.
00005 
00006 SUKITTI PUNAK   (11/08/2004)
00007 UPDATE          (11/08/2004)
00008 ******************************************************************************/
00009 #include "TAPsSpringVertex.hpp"
00010 // Using Inclusion Model (i.e. definitions are included in declarations)
00011 //                       (this name.cpp is included in name.hpp)
00012 // Each friend is defined directly inside its declaration.
00013 
00014 BEGIN_NAMESPACE_TAPs
00015 //=============================================================================
00016 // Constructors and Destructor
00017 //-----------------------------------------------------------------------------
00018 // SpringVertex Constructor
00019 template <typename T>
00020 SpringVertex<T>::SpringVertex
00021 (
00022     ParticleVertex<T> &P1, 
00023     ParticleVertex<T> &P2, 
00024     T k, T d, T l 
00025 )   : 
00026     m_rcP1( P1 ), 
00027     m_rcP2( P2 ), 
00028     m_tK( k ), 
00029     m_tD( d ), 
00030     m_tL( l )
00031 {}
00032 //-----------------------------------------------------------------------------
00033 // SpringVertex Constructor
00034 template <typename T>
00035 SpringVertex<T>::SpringVertex
00036 (
00037     ParticleVertex<T> &P1, 
00038     ParticleVertex<T> &P2, 
00039     T k, T d
00040 )   : 
00041     m_rcP1( P1 ), 
00042     m_rcP2( P2 ), 
00043     m_tK( k ), 
00044     m_tD( d )
00045 {
00046     T x = P2.GetPosition().GetX() - P1.GetPosition().GetX();
00047     T y = P2.GetPosition().GetY() - P1.GetPosition().GetY();
00048     T z = P2.GetPosition().GetZ() - P1.GetPosition().GetZ();
00049     m_tL = sqrt( x*x + y*y + z*z );
00050 }
00051 //-----------------------------------------------------------------------------
00052 // SpringVertex Destructor
00053 template <typename T>
00054 SpringVertex<T>::~SpringVertex()
00055 {}
00056 //-----------------------------------------------------------------------------
00057 //=============================================================================
00058 // Calculate and Return the (Internal) Force of a Spring
00059 //-----------------------------------------------------------------------------
00060 template <typename T>
00061 Vector3<T> SpringVertex<T>::GetForce() const
00062 {
00063     // Local Variables ---------------------------------------------------------
00064     // spring current length vector
00065     Vector3<T> cL = ( m_rcP1.GetPosition() - m_rcP2.GetPosition() );
00066     // spring current length scalar
00067     T scl = cL.Length();
00068     // velocity difference of the two particles linked by the spring
00069     Vector3<T> V = ( m_rcP1.GetVelocity() - m_rcP2.GetVelocity() );
00070 
00071     // F1 = -{Ks(l - r) + Kd[(V1-V2)*L]/l}*L/l
00072     // F2 = -F1
00073     //   where Ks = spring stiffness, Kd = spring damping,
00074     //     V1 and V2 are velocity of particles linked by the spring
00075     //     r = spring rest length
00076     //     L = vector of difference of positions of particle#1 and #2
00077     //     l = magnitude of L
00078     return -( (m_tK * (scl - m_tL)) +  (m_tD * ((V*cL) / scl)) ) * (cL / scl);
00079 }
00080 //-----------------------------------------------------------------------------
00081 //=============================================================================
00082 // Get/Set Functions
00083 //-----------------------------------------------------------------------------
00084 // Get Particle #1
00085 template <typename T>
00086 inline ParticleVertex<T> & SpringVertex<T>::GetParticleVertexOne ()
00087 {   return m_rcP1;  }
00088 //-----------------------------------------------------------------------------
00089 // Get Particle #2
00090 template <typename T>
00091 inline ParticleVertex<T> & SpringVertex<T>::GetParticleVertexTwo ()
00092 {   return m_rcP2;  }
00093 //-----------------------------------------------------------------------------
00094 // Get Constant K
00095 template <typename T>
00096 inline T SpringVertex<T>::GetConstantK () const
00097 {   return m_tK;    }
00098 //-----------------------------------------------------------------------------
00099 // Get Damping D
00100 template <typename T>
00101 inline T SpringVertex<T>::GetDampingD () const
00102 {   return m_tD;    }
00103 //-----------------------------------------------------------------------------
00104 // Get Rest Length L
00105 template <typename T>
00106 inline T SpringVertex<T>::GetRestLengthL() const
00107 {   return m_tL;    }
00108 //-----------------------------------------------------------------------------
00109 // Get Current Length
00110 template <typename T>
00111 inline T SpringVertex<T>::GetCurrentLength() const
00112 {   return ( m_rcP1.GetPosition() - m_rcP2.GetPosition() ).Length();    }
00113 //-----------------------------------------------------------------------------
00114 //=============================================================================
00115 END_NAMESPACE_TAPs
00116 //345678901234567890123456789012345678901234567890123456789012345678901234567890
00117 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines