My Project
Loading...
Searching...
No Matches
CGELLinearSpring.h
Go to the documentation of this file.
1//===========================================================================
2/*
3 Software License Agreement (BSD License)
4 Copyright (c) 2003-2024, CHAI3D
5 (www.chai3d.org)
6
7 All rights reserved.
8
9 Redistribution and use in source and binary forms, with or without
10 modification, are permitted provided that the following conditions
11 are met:
12
13 * Redistributions of source code must retain the above copyright
14 notice, this list of conditions and the following disclaimer.
15
16 * Redistributions in binary form must reproduce the above
17 copyright notice, this list of conditions and the following
18 disclaimer in the documentation and/or other materials provided
19 with the distribution.
20
21 * Neither the name of CHAI3D nor the names of its contributors may
22 be used to endorse or promote products derived from this software
23 without specific prior written permission.
24
25 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
28 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
29 COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
30 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
31 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
33 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
35 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 POSSIBILITY OF SUCH DAMAGE.
37
38 \author <http://www.chai3d.org>
39 \author Francois Conti
40 \version 1.0.0
41*/
42//===========================================================================
43
44//---------------------------------------------------------------------------
45#ifndef CGELLinearSpringH
46#define CGELLinearSpringH
47//---------------------------------------------------------------------------
48#include "CGELMassParticle.h"
49//---------------------------------------------------------------------------
50#include "chai3d.h"
51//---------------------------------------------------------------------------
52
53//===========================================================================
60//===========================================================================
61
62//===========================================================================
70//===========================================================================
72{
73 //-----------------------------------------------------------------------
74 // CONSTRUCTOR & DESTRUCTOR:
75 //-----------------------------------------------------------------------
76
77public:
78
81
84
85
86 //-----------------------------------------------------------------------
87 // PUBLIC METHODS:
88 //-----------------------------------------------------------------------
89
90public:
91
92 //-----------------------------------------------------------------------
97 //-----------------------------------------------------------------------
98 inline void render()
99 {
100#ifdef C_USE_OPENGL
101
102 // render link
103 glColor4fv( (const float *)&m_color);
104 glBegin(GL_LINES);
105 glVertex3dv( (const double *)&m_node0->m_pos);
106 glVertex3dv( (const double *)&m_node1->m_pos);
107 glEnd();
108
109#endif
110 }
111
112
113 //-----------------------------------------------------------------------
118 //-----------------------------------------------------------------------
119 inline void computeForces()
120 {
121 // update basic parameters of current link
122 chai3d::cVector3d m_link01 = cSub(m_node1->m_pos, m_node0->m_pos);
123 double m_length = m_link01.length();
124
125 //-------------------------------------------------------------
126 // ELONGATION:
127 //-------------------------------------------------------------
128 // if distance too small, no forces are applied
129 if (m_length < 0.000001) { return; }
130
131 // elongation compute force
132 double f = m_kSpringElongation * (m_length - m_length0);
133
134 // apply force
135 if (m_length > 0.000001)
136 {
137 chai3d::cVector3d force = cMul(f/m_length, m_link01);
138 m_node0->addForce(force);
139 chai3d::cVector3d tmpfrc = cMul(-1, force);
140 m_node1->addForce(tmpfrc);
141 }
142 }
143
144
145 //-----------------------------------------------------------------------
146 // PUBLIC MEMBERS - GRAPHICAL PROPERTIES:
147 //-----------------------------------------------------------------------
148
149public:
150
153
154
155 //-----------------------------------------------------------------------
156 // PUBLIC MEMBERS - MASS NODES:
157 //-----------------------------------------------------------------------
158
159public:
160
163
166
167
168 //-----------------------------------------------------------------------
169 // PUBLIC MEMBERS - PHYSICAL PROPERTIES:
170 //-----------------------------------------------------------------------
171
172public:
173
176
179
182
184 double m_length0;
185
186
187 //-----------------------------------------------------------------------
188 // STATIC MEMBERS - DEFAULT SETTINGS:
189 //-----------------------------------------------------------------------
190
191public:
192
194 static double s_default_kSpringElongation; // [N/m]
195
198};
199
200//---------------------------------------------------------------------------
201#endif
202//---------------------------------------------------------------------------
203
Implementation of a mass particle.
This class implements a linear spring between two mass particles.
Definition CGELLinearSpring.h:72
static double s_default_kSpringElongation
Default property - linear stiffness.
Definition CGELLinearSpring.h:194
chai3d::cColorf m_color
Color property used for displaying link.
Definition CGELLinearSpring.h:152
double m_kDamperElongation
Linear damping.
Definition CGELLinearSpring.h:181
double m_kSpringElongation
Linear spring constant.
Definition CGELLinearSpring.h:175
static chai3d::cColorf s_default_color
Default property - color property.
Definition CGELLinearSpring.h:197
cGELMassParticle * m_node1
Node 1 of current link.
Definition CGELLinearSpring.h:165
double m_length0
Initial length of link.
Definition CGELLinearSpring.h:184
void computeForces()
This method computes the forces that are applied on the mass nodes.
Definition CGELLinearSpring.h:119
~cGELLinearSpring()
Destructor of cGELLinearSpring.
Definition CGELLinearSpring.cpp:94
bool m_enabled
Is link enabled?
Definition CGELLinearSpring.h:178
void render()
This method graphically renders this spring using OpenGL.
Definition CGELLinearSpring.h:98
cGELMassParticle * m_node0
Node 0 of current link.
Definition CGELLinearSpring.h:162
This class implements a simple mass particle point.
Definition CGELMassParticle.h:70
void addForce(chai3d::cVector3d &a_force)
This method adds a force to this mass particle.
Definition CGELMassParticle.h:94
chai3d::cVector3d m_pos
Position of particle.
Definition CGELMassParticle.h:220
double length() const