aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--msd/help-msd.pd220
-rwxr-xr-xmsd/main.cpp104
-rw-r--r--msd2D/help-msd2D.pd239
-rwxr-xr-xmsd2D/main.cpp124
-rw-r--r--msd3D/filet.pd80
-rw-r--r--msd3D/help-msd3D.pd247
-rwxr-xr-xmsd3D/main.cpp120
7 files changed, 718 insertions, 416 deletions
diff --git a/msd/help-msd.pd b/msd/help-msd.pd
index 80d792d..e77b750 100644
--- a/msd/help-msd.pd
+++ b/msd/help-msd.pd
@@ -1,76 +1,170 @@
-#N canvas 0 0 794 877 10;
+#N canvas 367 274 570 449 10;
+#N canvas 271 52 742 843 masses 1;
#X obj 33 821 msd;
-#X obj 62 14 cnv 15 610 305 empty empty CREATION 20 12 0 14 -262131
+#X obj 62 154 cnv 15 610 180 empty empty CREATION 20 12 0 14 -262131
-66577 0;
-#X msg 79 43 reset;
-#X text 249 74 Add a mass;
-#X text 335 75 \$1 : Id (symbol);
-#X text 334 95 \$2 : fixed or mobile (0/1);
-#X text 334 113 \$3 : mass;
-#X text 334 151 \$1 : Id (symbol);
-#X text 246 151 Add a link;
-#X text 333 171 \$2 : creation No of mass1;
-#X text 333 189 \$3 : creation No of mass2;
-#X text 332 207 \$4 : rigidity;
-#X text 251 44 Delete all masses and links;
-#X text 332 225 \$5 : viscosity;
-#X text 332 242 \$6 : damping;
-#X obj 62 324 cnv 15 610 60 empty empty COMPUTATION 20 12 0 14 -261689
+#X msg 79 183 reset;
+#X text 249 214 Add a mass;
+#X text 335 215 \$1 : Id (symbol);
+#X text 334 235 \$2 : fixed or mobile (0/1);
+#X text 334 253 \$3 : mass;
+#X text 251 184 Delete all masses and links;
+#X obj 62 338 cnv 15 610 60 empty empty COMPUTATION 20 12 0 14 -261689
-66577 0;
-#X msg 82 353 bang;
-#X text 235 353 Compute new masses positions;
-#X obj 61 388 cnv 15 610 220 empty empty DYNAMIC_SETTING 20 12 0 14
+#X msg 82 367 bang;
+#X text 235 367 Compute new masses positions;
+#X obj 61 403 cnv 15 610 210 empty empty DYNAMIC_SETTING 20 12 0 14
-262131 -66577 0;
-#X msg 169 410 setD \$1 \$2;
-#X text 354 428 \$1 : Id (symbol);
-#X text 354 446 \$2 : New value;
-#X msg 87 410 setK \$1 \$2;
-#X text 350 482 \$1 : Id (symbol);
-#X text 350 500 \$2 : New value;
-#X text 348 539 \$1 : Id (symbol);
-#X text 348 557 \$2 : New value;
-#X msg 87 462 posX \$1 \$2;
-#X text 350 464 Set position of mass(es);
-#X text 347 522 Add force on mass(es);
-#X msg 85 521 forceX \$1 \$2;
-#X msg 255 410 setD2 \$1 \$2;
-#X text 354 410 Set rigidity \, viscosity or damping of link(s);
-#X obj 60 617 cnv 15 610 198 empty empty GET_ATTRIBUTES 20 12 0 14
+#X text 350 449 \$1 : Id (symbol);
+#X text 350 467 \$2 : New value;
+#X text 348 503 \$1 : Id (symbol);
+#X text 348 521 \$2 : New value;
+#X msg 87 429 posX \$1 \$2;
+#X text 350 431 Set position of mass(es);
+#X text 347 486 Add force on mass(es);
+#X msg 85 485 forceX \$1 \$2;
+#X obj 61 617 cnv 15 610 198 empty empty GET_ATTRIBUTES 20 12 0 14
-261689 -66577 0;
-#X msg 146 644 massePosL;
-#X msg 146 672 masseForcesL;
-#X text 247 644 output all masses positions in a list on outlet No
+#X msg 147 644 massePosL;
+#X msg 147 672 masseForcesL;
+#X text 248 644 output all masses positions in a list on outlet No
1;
-#X text 246 673 output all masses forces in a list on outlet No 1;
-#X msg 145 710 get \$1 \$2;
-#X text 248 711 Get specific attribute;
-#X text 248 736 \$1 : Attribute type ( massesPos / massesSpeeds / massesForces
+#X text 247 673 output all masses forces in a list on outlet No 1;
+#X msg 146 710 get \$1 \$2;
+#X text 249 711 Get specific attribute;
+#X text 249 736 \$1 : Attribute type ( massesPos / massesSpeeds / massesForces
/ linksPos );
-#X text 248 773 \$2 : Id (symbol or creations numbers);
-#X text 334 131 \$4 : position;
-#X msg 79 74 mass \$1 \$2 \$3 \$4;
-#X msg 76 151 link \$1 \$2 \$3 \$4 \$5 \$6;
-#X msg 75 258 deleteMass \$1;
-#X text 240 260 Delete a mass and associated links;
-#X text 330 277 \$1 : Creation No of mass;
-#X msg 74 294 deleteLink \$1;
-#X text 239 296 Delete a link;
-#X text 340 296 \$1 : Creation No of link;
-#X msg 143 793 infosL;
-#X text 246 793 Get infos on all masses and links on outlet No 2;
-#X msg 84 573 Xmin \$1 \, Xmax \$1;
-#X text 347 576 Set minimimum and maximum X of masses;
-#X text 347 593 \$1 : Value;
+#X text 249 773 \$2 : Id (symbol or creations numbers);
+#X msg 79 214 mass \$1 \$2 \$3 \$4;
+#X msg 79 290 deleteMass \$1;
+#X text 248 292 Delete a mass and associated links;
+#X text 338 309 \$1 : Creation No of mass;
+#X msg 144 793 infosL;
+#X text 247 793 Get infos on all masses and links on outlet No 2;
+#X msg 84 535 Xmin \$1 \, Xmax \$1;
+#X text 347 538 Set minimimum and maximum X of masses;
+#X text 347 555 \$1 : Value;
+#X text 73 22 MASSES :;
+#X text 66 69 They got only one physical parameter \, the value of
+their;
+#X text 67 83 mass. They can be mobile or fixed \, in this case forces
+;
+#X text 67 54 The msd masses are the principals objects of the model.
+;
+#X text 66 97 applied on them automatically \, by links \, or manually
+\, by;
+#X text 67 112 messages \, don't do anything.;
+#X msg 81 574 setMobile \$1 \, setFixed \$1;
+#X text 345 578 Change mobile parameter;
+#X text 345 594 \$1 : Creation No of mass;
+#X text 334 271 \$4 : initial position;
#X connect 2 0 0 0;
+#X connect 9 0 0 0;
#X connect 16 0 0 0;
+#X connect 19 0 0 0;
+#X connect 21 0 0 0;
#X connect 22 0 0 0;
-#X connect 27 0 0 0;
+#X connect 25 0 0 0;
+#X connect 29 0 0 0;
#X connect 30 0 0 0;
-#X connect 34 0 0 0;
+#X connect 33 0 0 0;
#X connect 35 0 0 0;
-#X connect 38 0 0 0;
-#X connect 43 0 0 0;
#X connect 44 0 0 0;
-#X connect 45 0 0 0;
-#X connect 48 0 0 0;
-#X connect 51 0 0 0;
+#X restore 281 323 pd masses;
+#N canvas 222 83 808 841 links 0;
+#X obj 33 821 msd;
+#X obj 62 250 cnv 15 610 305 empty empty CREATION 20 12 0 14 -262131
+-66577 0;
+#X msg 79 279 reset;
+#X text 338 308 \$1 : Id (symbol);
+#X text 250 308 Add a link;
+#X text 337 328 \$2 : creation No of mass1;
+#X text 337 346 \$3 : creation No of mass2;
+#X text 336 364 \$4 : rigidity;
+#X text 251 280 Delete all masses and links;
+#X text 336 382 \$5 : viscosity;
+#X text 336 399 \$6 : damping;
+#X obj 61 561 cnv 15 610 82 empty empty DYNAMIC_SETTING 20 12 0 14
+-262131 -66577 0;
+#X msg 172 583 setD \$1 \$2;
+#X text 354 601 \$1 : Id (symbol);
+#X text 354 619 \$2 : New value;
+#X msg 87 583 setK \$1 \$2;
+#X msg 255 583 setD2 \$1 \$2;
+#X text 354 583 Set rigidity \, viscosity or damping of link(s);
+#X obj 60 650 cnv 15 610 140 empty empty GET_ATTRIBUTES 20 12 0 14
+-261689 -66577 0;
+#X msg 75 679 get \$1 \$2;
+#X text 237 680 Get specific attribute;
+#X text 237 705 \$1 : Attribute type ( massesPos / massesSpeeds / massesForces
+/ linksPos );
+#X text 237 742 \$2 : Id (symbol or creations numbers);
+#X msg 78 308 link \$1 \$2 \$3 \$4 \$5 \$6;
+#X msg 74 532 deleteLink \$1;
+#X text 239 534 Delete a link;
+#X text 340 534 \$1 : Creation No of link;
+#X msg 73 762 infosL;
+#X text 236 762 Get infos on all masses and links on outlet No 2;
+#X msg 73 423 iLink \$1 \$2 \$3 \$4 \$5 \$6;
+#X text 338 308 \$1 : Id (symbol);
+#X text 250 308 Add a link;
+#X text 337 328 \$2 : creation No of mass1;
+#X text 337 346 \$3 : creation No of mass2;
+#X text 336 364 \$4 : rigidity;
+#X text 336 382 \$5 : viscosity;
+#X text 336 399 \$6 : damping;
+#X text 410 422 \$1 : Id (symbol);
+#X text 409 478 \$4 : rigidity;
+#X text 409 496 \$5 : viscosity;
+#X text 409 513 \$6 : damping;
+#X text 410 422 \$1 : Id (symbol);
+#X text 409 478 \$4 : rigidity;
+#X text 409 496 \$5 : viscosity;
+#X text 409 513 \$6 : damping;
+#X text 248 423 Add an interactor link;
+#X text 94 52 LINKS :;
+#X text 71 91 parameters : length \, rigidity \, viscosity and damping.
+;
+#X text 72 78 Links connect masses two by two. They got 4 physicals
+;
+#X text 70 134 the two masses at the creation.;
+#X text 71 120 message. The lenght is initialised to the distance between
+;
+#X text 71 106 Rigidity \, viscosity and damping are defined by the
+creation;
+#X text 409 442 \$2 : Id (symbol) of masses type 1;
+#X text 409 460 \$3 : Id (symbol) of masses type 2;
+#X text 70 148 Interactor links are links between mutiples masses \,
+instead;
+#X text 70 161 of creation number \, the masses linked are defined
+with;
+#X text 69 175 their Id.;
+#X connect 2 0 0 0;
+#X connect 15 0 0 0;
+#X connect 19 0 0 0;
+#X connect 23 0 0 0;
+#X connect 24 0 0 0;
+#X connect 27 0 0 0;
+#X connect 29 0 0 0;
+#X restore 283 353 pd links;
+#X text 135 323 HELP on masses --->;
+#X text 134 354 HELP on links --->;
+#X text 154 34 MSD : mass - spring - damper model;
+#X text 75 79 MSD is the 1D object of the msd objects collection.;
+#X text 73 128 There are 4 types of messages for msd :;
+#X text 74 92 It is designed to implement particules physical model
+in PD.The model is based on two elements type : mass and link.;
+#X obj 73 143 cnv 15 420 30 empty empty empty 20 12 0 14 -262131 -66577
+0;
+#X obj 73 176 cnv 15 420 30 empty empty empty 20 12 0 14 -261689 -66577
+0;
+#X obj 73 209 cnv 15 420 30 empty empty empty 20 12 0 14 -262131 -66577
+0;
+#X obj 73 242 cnv 15 420 30 empty empty empty 20 12 0 14 -261689 -66577
+0;
+#X text 76 150 CREATION : To create the model masses and links.;
+#X text 76 215 DYNAMIC SETTING : To set the model parameters dynamically.
+;
+#X text 76 248 ATTRIBUTES : To get the model parameters.;
+#X text 76 177 COMPUTATION : To compute the new model state based on
+previous instant.;
diff --git a/msd/main.cpp b/msd/main.cpp
index b01bc5e..a9aad8a 100755
--- a/msd/main.cpp
+++ b/msd/main.cpp
@@ -101,7 +101,7 @@ public:
protected:
// --------------------------------------------------------------- RESET
-
+// ----------------------------------------------------------------------
void m_reset()
{
t_int i;
@@ -121,6 +121,7 @@ protected:
}
// -------------------------------------------------------------- COMPUTE
+// -----------------------------------------------------------------------
void m_bang()
{
@@ -130,37 +131,37 @@ protected:
for (i=0; i<nb_link; i++) {
// compute link forces
- distance = link[i]->mass1->posX-link[i]->mass2->posX;
- F = link[i]->K1 * (distance - link[i]->longueur) ; // F = k1(x1-x2)
- F += link[i]->D1 * (distance - link[i]->distance_old) ; // F = F + D1(v1-v2)
+ distance = link[i]->mass1->posX-link[i]->mass2->posX; // L[n] = x1 - x2
+ F = link[i]->K1 * (distance - link[i]->longueur) ; // F[n] = k1 (L[n] - L[0])
+ F += link[i]->D1 * (distance - link[i]->distance_old) ; // F[n] = F[n] + D1 (L[n] - L[n-1])
if (distance != 0) {
- Fx = F * (link[i]->mass1->posX - link[i]->mass2->posX)/distance;
+ Fx = F * (link[i]->mass1->posX - link[i]->mass2->posX)/distance; // Fx = F * Lx[n]/L[n]
}
- link[i]->mass1->forceX -= Fx;
- link[i]->mass1->forceX -= link[i]->D2*link[i]->mass1->speedX;
- link[i]->mass2->forceX += Fx;
- link[i]->mass2->forceX -= link[i]->D2*link[i]->mass2->speedX;
- link[i]->distance_old = distance;
+ link[i]->mass1->forceX -= Fx; // Fx1[n] = -Fx
+ link[i]->mass1->forceX -= link[i]->D2*link[i]->mass1->speedX; // Fx1[n] = Fx1[n] - D2 * vx1[n-1]
+ link[i]->mass2->forceX += Fx; // Fx2[n] = Fx
+ link[i]->mass2->forceX -= link[i]->D2*link[i]->mass2->speedX; // Fx2[n] = Fx2[n] - D2 * vx2[n-1]
+ link[i]->distance_old = distance; // L[n-1] = L[n]
}
for (i=0; i<nb_mass; i++)
// compute new masses position only if mobile = 1
if (mass[i]->mobile == 1) {
- X_new = mass[i]->forceX * mass[i]->invM + 2*mass[i]->posX - mass[i]->posX2;
- mass[i]->posX2 = mass[i]->posX;
- mass[i]->posX = max(min(X_new,Xmax),Xmin); // x = x + v
- mass[i]->speedX = mass[i]->posX - mass[i]->posX2; // v = v + F/M
+ X_new = mass[i]->forceX * mass[i]->invM + 2*mass[i]->posX - mass[i]->posX2; // x[n] =Fx[n]/M+2x[n]-x[n-1]
+ mass[i]->posX2 = mass[i]->posX; // x[n-2] = x[n-1]
+ mass[i]->posX = max(min(X_new,Xmax),Xmin); // x[n-1] = x[n]
+ mass[i]->speedX = mass[i]->posX - mass[i]->posX2; // vx[n] = x[n] - x[n-1]
}
for (i=0; i<nb_mass; i++) {
// clear forces
mass[i]->out_forceX = mass[i]->forceX;
- mass[i]->forceX = 0;
+ mass[i]->forceX = 0; // Fx[n] = 0
}
}
// -------------------------------------------------------------- MASSES
-
+// ----------------------------------------------------------------------
void m_mass(int argc,t_atom *argv)
// add a mass
// Id, nbr, mobile, invM, speedX, posX, forceX
@@ -168,18 +169,18 @@ protected:
t_atom sortie[5], aux[2];
t_float M;
- mass[nb_mass] = new t_mass; // new pointer
- mass[nb_mass]->Id = GetSymbol(argv[0]); // ID
+ mass[nb_mass] = new t_mass; // new mass
+ mass[nb_mass]->Id = GetSymbol(argv[0]); // ID
mass[nb_mass]->mobile = GetInt(argv[1]); // mobile
if (GetFloat(argv[2])==0)
M=1;
else M = GetFloat(argv[2]);
- mass[nb_mass]->invM = 1/(M); // invM
- mass[nb_mass]->speedX = 0; // vx
- mass[nb_mass]->posX = GetFloat(argv[3]); // x
- mass[nb_mass]->posX2 = GetFloat(argv[3]); // x
- mass[nb_mass]->forceX = 0; // Fx
- mass[nb_mass]->nbr = id_mass; // id_nbr
+ mass[nb_mass]->invM = 1/(M); // 1/M
+ mass[nb_mass]->speedX = 0; // vx[n]
+ mass[nb_mass]->posX = GetFloat(argv[3]); // x[n]
+ mass[nb_mass]->posX2 = GetFloat(argv[3]); // x[n-1]
+ mass[nb_mass]->forceX = 0; // Fx[n]
+ mass[nb_mass]->nbr = id_mass; // id number
nb_mass++ ;
id_mass++;
nb_mass = min ( nb_max_mass -1, nb_mass );
@@ -252,6 +253,8 @@ protected:
t_int i,nb_link_delete=0;
t_atom sortie[5], aux[nb_link];
+
+ // Delete all associated links
for (i=0; i<nb_link;i++) {
if (link[i]->mass1->nbr == GetAInt(argv[0]) || link[i]->mass2->nbr == GetAInt(argv[0])) {
SetFloat((aux[nb_link_delete]),link[i]->nbr);
@@ -261,7 +264,8 @@ protected:
for (i=0; i<nb_link_delete;i++)
m_delete_link(1,&aux[i]);
-
+
+ // Delete mass
for (i=0; i<nb_mass;i++)
if (mass[i]->nbr == GetAInt(argv[0])) {
SetFloat((sortie[0]),mass[i]->nbr);
@@ -270,7 +274,7 @@ protected:
SetFloat((sortie[3]),1/mass[i]->invM);
SetFloat((sortie[4]),mass[i]->posX);
delete mass[i];
- mass[i] = mass[nb_mass-1];
+ mass[i] = mass[nb_mass-1]; // copy last mass instead
nb_mass--;
ToOutAnything(1,S_Mass_deleted,5,sortie);
break;
@@ -281,17 +285,18 @@ protected:
void m_Xmax(int argc,t_atom *argv)
{
- // set damping of link(s) named Id
+ // set X max
Xmax = GetFloat(argv[0]);
}
void m_Xmin(int argc,t_atom *argv)
{
- // set damping of link(s) named Id
+ // set X min
Xmin = GetFloat(argv[0]);
}
// -------------------------------------------------------------- LINKS
+// ---------------------------------------------------------------------
void m_link(int argc,t_atom *argv)
// add a link
@@ -300,20 +305,20 @@ protected:
t_atom sortie[7], aux[2];
t_int i;
- link[nb_link] = new t_link;
- link[nb_link]->Id = GetSymbol(argv[0]);
+ link[nb_link] = new t_link; // New pointer
+ link[nb_link]->Id = GetSymbol(argv[0]); // ID
for (i=0; i<nb_mass;i++)
- if (mass[i]->nbr==GetAInt(argv[1]))
+ if (mass[i]->nbr==GetAInt(argv[1])) // pointer to mass1
link[nb_link]->mass1 = mass[i];
- else if(mass[i]->nbr==GetAInt(argv[2]))
+ else if(mass[i]->nbr==GetAInt(argv[2])) // pointer to mass2
link[nb_link]->mass2 = mass[i];
- link[nb_link]->K1 = GetFloat(argv[3]);
- link[nb_link]->D1 = GetFloat(argv[4]);
- link[nb_link]->D2 = GetFloat(argv[5]);
- link[nb_link]->longx = link[nb_link]->mass1->posX - link[nb_link]->mass2->posX;
- link[nb_link]->longueur = link[nb_link]->longx ;
- link[nb_link]->nbr = id_link;
- link[nb_link]->distance_old = link[nb_link]->longueur;
+ link[nb_link]->K1 = GetFloat(argv[3]); // K1
+ link[nb_link]->D1 = GetFloat(argv[4]); // D1
+ link[nb_link]->D2 = GetFloat(argv[5]); // D2
+ link[nb_link]->longx = link[nb_link]->mass1->posX - link[nb_link]->mass2->posX; // Lx[0]
+ link[nb_link]->longueur = link[nb_link]->longx ;// L[0]
+ link[nb_link]->nbr = id_link; // id number
+ link[nb_link]->distance_old = link[nb_link]->longueur; // L[n-1]
nb_link++;
id_link++;
nb_link = min ( nb_max_link -1, nb_link );
@@ -356,7 +361,7 @@ protected:
SetSymbol((arglist[0]),GetSymbol(argv[0]));
SetFloat((arglist[1]),mass[imass1[i]]->nbr);
SetFloat((arglist[2]),mass[imass2[j]]->nbr);
- SetFloat((arglist[3]),GetInt(argv[3]));
+ SetFloat((arglist[3]),GetFloat(argv[3]));
SetFloat((arglist[4]),GetFloat(argv[4]));
SetFloat((arglist[5]),GetFloat(argv[5]));
m_link(6,arglist);
@@ -418,7 +423,7 @@ protected:
SetFloat((sortie[5]),link[i]->D1);
SetFloat((sortie[6]),link[i]->D2);
delete link[i];
- link[i]=link[nb_link-1];
+ link[i]=link[nb_link-1]; // copy last link instead
nb_link--;
ToOutAnything(1,S_Link_deleted,7,sortie);
break;
@@ -427,6 +432,7 @@ protected:
// -------------------------------------------------------------- GET
+// -------------------------------------------------------------------
void m_get(int argc,t_atom *argv)
// get attributes
@@ -595,7 +601,7 @@ protected:
}
void m_force_dumpl()
- // List of masses positions on first outlet
+ // List of masses forces on first outlet
{
t_atom sortie[nb_mass];
t_int i;
@@ -607,7 +613,7 @@ protected:
}
void m_info_dumpl()
- // List of masses positions on first outlet
+ // List of masses and links infos on first outlet
{
t_atom sortie[7];
t_int i;
@@ -636,16 +642,19 @@ protected:
// -------------------------------------------------------------- PROTECTED VARIABLES
+// -----------------------------------------------------------------------------------
- t_link * link[nb_max_link];
- t_mass * mass[nb_max_mass];
- t_float Xmin, Xmax, Ymin, Ymax;
+ t_link * link[nb_max_link]; // Pointer table on links
+ t_mass * mass[nb_max_mass]; // Pointer table on masses
+ t_float Xmin, Xmax; // Limit values
int nb_link, nb_mass, id_mass, id_link;
// -------------------------------------------------------------- SETUP
+// ---------------------------------------------------------------------
private:
+ // Static symbols
const static t_symbol *S_Reset;
const static t_symbol *S_Mass;
const static t_symbol *S_Link;
@@ -721,7 +730,8 @@ private:
FLEXT_CALLBACK_V(m_delete_link)
FLEXT_CALLBACK_V(m_delete_mass)
};
-
+// -------------------------------------------------------------- STATIC VARIABLES
+// -------------------------------------------------------------------------------
const t_symbol *msd::S_Reset = MakeSymbol("Reset");
const t_symbol *msd::S_Mass = MakeSymbol("Mass");
diff --git a/msd2D/help-msd2D.pd b/msd2D/help-msd2D.pd
index 9662c14..d2f051a 100644
--- a/msd2D/help-msd2D.pd
+++ b/msd2D/help-msd2D.pd
@@ -1,78 +1,173 @@
-#N canvas 0 0 823 885 10;
-#X obj 51 13 cnv 15 610 305 empty empty CREATION 20 12 0 14 -262131
+#N canvas 0 0 478 397 10;
+#N canvas 271 52 742 843 masses 1;
+#X obj 62 154 cnv 15 610 180 empty empty CREATION 20 12 0 14 -262131
-66577 0;
-#X msg 68 42 reset;
-#X text 238 73 Add a mass;
-#X text 324 74 \$1 : Id (symbol);
-#X text 323 94 \$2 : fixed or mobile (0/1);
-#X text 323 112 \$3 : mass;
-#X text 323 150 \$1 : Id (symbol);
-#X text 235 150 Add a link;
-#X text 322 170 \$2 : creation No of mass1;
-#X text 322 188 \$3 : creation No of mass2;
-#X text 321 206 \$4 : rigidity;
-#X text 240 43 Delete all masses and links;
-#X text 321 224 \$5 : viscosity;
-#X text 321 241 \$6 : damping;
-#X obj 51 323 cnv 15 610 60 empty empty COMPUTATION 20 12 0 14 -261689
+#X msg 79 183 reset;
+#X text 249 214 Add a mass;
+#X text 335 215 \$1 : Id (symbol);
+#X text 334 235 \$2 : fixed or mobile (0/1);
+#X text 334 253 \$3 : mass;
+#X text 251 184 Delete all masses and links;
+#X obj 62 338 cnv 15 610 60 empty empty COMPUTATION 20 12 0 14 -261689
-66577 0;
-#X msg 71 352 bang;
-#X text 224 352 Compute new masses positions;
-#X obj 50 387 cnv 15 610 220 empty empty DYNAMIC_SETTING 20 12 0 14
+#X msg 82 367 bang;
+#X text 235 367 Compute new masses positions;
+#X obj 61 403 cnv 15 610 210 empty empty DYNAMIC_SETTING 20 12 0 14
-262131 -66577 0;
-#X msg 158 409 setD \$1 \$2;
-#X text 343 427 \$1 : Id (symbol);
-#X text 343 445 \$2 : New value;
-#X msg 76 409 setK \$1 \$2;
-#X text 339 481 \$1 : Id (symbol);
-#X text 339 499 \$2 : New value;
-#X text 337 538 \$1 : Id (symbol);
-#X text 337 556 \$2 : New value;
-#X msg 76 461 posX \$1 \$2;
-#X text 339 463 Set position of mass(es);
-#X text 336 521 Add force on mass(es);
-#X msg 74 520 forceX \$1 \$2;
-#X msg 244 409 setD2 \$1 \$2;
-#X text 343 409 Set rigidity \, viscosity or damping of link(s);
-#X obj 49 616 cnv 15 610 198 empty empty GET_ATTRIBUTES 20 12 0 14
+#X text 350 449 \$1 : Id (symbol);
+#X text 350 467 \$2 : New value;
+#X text 348 503 \$1 : Id (symbol);
+#X text 348 521 \$2 : New value;
+#X msg 87 429 posX \$1 \$2;
+#X text 350 431 Set position of mass(es);
+#X text 347 486 Add force on mass(es);
+#X msg 85 485 forceX \$1 \$2;
+#X obj 61 617 cnv 15 610 198 empty empty GET_ATTRIBUTES 20 12 0 14
-261689 -66577 0;
-#X msg 135 643 massePosL;
-#X msg 135 671 masseForcesL;
-#X text 236 643 output all masses positions in a list on outlet No
+#X msg 147 644 massePosL;
+#X msg 147 672 masseForcesL;
+#X text 248 644 output all masses positions in a list on outlet No
1;
-#X text 235 672 output all masses forces in a list on outlet No 1;
-#X msg 134 709 get \$1 \$2;
-#X text 237 710 Get specific attribute;
-#X text 237 735 \$1 : Attribute type ( massesPos / massesSpeeds / massesForces
+#X text 247 673 output all masses forces in a list on outlet No 1;
+#X msg 146 710 get \$1 \$2;
+#X text 249 711 Get specific attribute;
+#X text 249 736 \$1 : Attribute type ( massesPos / massesSpeeds / massesForces
/ linksPos );
-#X text 237 772 \$2 : Id (symbol or creations numbers);
-#X msg 65 150 link \$1 \$2 \$3 \$4 \$5 \$6;
-#X msg 64 257 deleteMass \$1;
-#X text 229 259 Delete a mass and associated links;
-#X text 319 276 \$1 : Creation No of mass;
-#X msg 63 293 deleteLink \$1;
-#X text 228 295 Delete a link;
-#X text 329 295 \$1 : Creation No of link;
-#X msg 132 792 infosL;
-#X text 235 792 Get infos on all masses and links on outlet No 2;
-#X text 336 592 \$1 : Value;
-#X obj 22 820 msd2D;
-#X msg 169 519 forceY \$1 \$2;
-#X msg 158 461 posY \$1 \$2;
-#X msg 68 73 mass \$1 \$2 \$3 \$4 \$5;
-#X text 323 130 \$4 \, \$5 : position;
-#X msg 73 572 Xmin \$1 \, Xmax \$1 \, Ymin \$1 \, Ymax \$1;
-#X text 336 575 Set minimimum and maximum of masses positions;
-#X connect 1 0 51 0;
-#X connect 15 0 51 0;
-#X connect 21 0 51 0;
-#X connect 26 0 51 0;
-#X connect 29 0 51 0;
-#X connect 33 0 51 0;
-#X connect 34 0 51 0;
-#X connect 37 0 51 0;
-#X connect 41 0 51 0;
-#X connect 42 0 51 0;
-#X connect 45 0 51 0;
-#X connect 48 0 51 0;
-#X connect 54 0 51 0;
+#X text 249 773 \$2 : Id (symbol or creations numbers);
+#X msg 79 290 deleteMass \$1;
+#X text 248 292 Delete a mass and associated links;
+#X text 338 309 \$1 : Creation No of mass;
+#X msg 144 793 infosL;
+#X text 247 793 Get infos on all masses and links on outlet No 2;
+#X text 347 555 \$1 : Value;
+#X text 73 22 MASSES :;
+#X text 66 69 They got only one physical parameter \, the value of
+their;
+#X text 67 83 mass. They can be mobile or fixed \, in this case forces
+;
+#X text 67 54 The msd masses are the principals objects of the model.
+;
+#X text 66 97 applied on them automatically \, by links \, or manually
+\, by;
+#X text 67 112 messages \, don't do anything.;
+#X msg 81 578 setMobile \$1 \, setFixed \$1;
+#X text 345 578 Change mobile parameter;
+#X text 345 594 \$1 : Creation No of mass;
+#X msg 79 214 mass \$1 \$2 \$3 \$4 \$5;
+#X msg 188 430 posY \$1 \$2;
+#X msg 186 486 forceY \$1 \$2;
+#X obj 33 821 msd2D;
+#X text 347 538 Set minimimum and maximum X \, Y of masses;
+#X msg 84 538 Xmin \$1 \, Xmax \$1 \, Ymin \$1 \, Ymax \$1;
+#X text 334 271 \$4 \, \$5 : initial position;
+#X connect 1 0 46 0;
+#X connect 8 0 46 0;
+#X connect 15 0 46 0;
+#X connect 18 0 46 0;
+#X connect 20 0 46 0;
+#X connect 21 0 46 0;
+#X connect 24 0 46 0;
+#X connect 28 0 46 0;
+#X connect 31 0 46 0;
+#X connect 40 0 46 0;
+#X connect 43 0 46 0;
+#X connect 48 0 46 0;
+#X restore 221 312 pd masses;
+#N canvas 222 83 808 841 links 0;
+#X obj 62 250 cnv 15 610 305 empty empty CREATION 20 12 0 14 -262131
+-66577 0;
+#X msg 79 279 reset;
+#X text 338 308 \$1 : Id (symbol);
+#X text 250 308 Add a link;
+#X text 337 328 \$2 : creation No of mass1;
+#X text 337 346 \$3 : creation No of mass2;
+#X text 336 364 \$4 : rigidity;
+#X text 251 280 Delete all masses and links;
+#X text 336 382 \$5 : viscosity;
+#X text 336 399 \$6 : damping;
+#X obj 61 561 cnv 15 610 82 empty empty DYNAMIC_SETTING 20 12 0 14
+-262131 -66577 0;
+#X msg 172 583 setD \$1 \$2;
+#X text 354 601 \$1 : Id (symbol);
+#X text 354 619 \$2 : New value;
+#X msg 87 583 setK \$1 \$2;
+#X msg 255 583 setD2 \$1 \$2;
+#X text 354 583 Set rigidity \, viscosity or damping of link(s);
+#X obj 60 650 cnv 15 610 140 empty empty GET_ATTRIBUTES 20 12 0 14
+-261689 -66577 0;
+#X msg 75 679 get \$1 \$2;
+#X text 237 680 Get specific attribute;
+#X text 237 705 \$1 : Attribute type ( massesPos / massesSpeeds / massesForces
+/ linksPos );
+#X text 237 742 \$2 : Id (symbol or creations numbers);
+#X msg 78 308 link \$1 \$2 \$3 \$4 \$5 \$6;
+#X msg 74 532 deleteLink \$1;
+#X text 239 534 Delete a link;
+#X text 340 534 \$1 : Creation No of link;
+#X msg 73 762 infosL;
+#X text 236 762 Get infos on all masses and links on outlet No 2;
+#X msg 73 423 iLink \$1 \$2 \$3 \$4 \$5 \$6;
+#X text 338 308 \$1 : Id (symbol);
+#X text 250 308 Add a link;
+#X text 337 328 \$2 : creation No of mass1;
+#X text 337 346 \$3 : creation No of mass2;
+#X text 336 364 \$4 : rigidity;
+#X text 336 382 \$5 : viscosity;
+#X text 336 399 \$6 : damping;
+#X text 410 422 \$1 : Id (symbol);
+#X text 409 478 \$4 : rigidity;
+#X text 409 496 \$5 : viscosity;
+#X text 409 513 \$6 : damping;
+#X text 410 422 \$1 : Id (symbol);
+#X text 409 478 \$4 : rigidity;
+#X text 409 496 \$5 : viscosity;
+#X text 409 513 \$6 : damping;
+#X text 248 423 Add an interactor link;
+#X text 94 52 LINKS :;
+#X text 71 91 parameters : length \, rigidity \, viscosity and damping.
+;
+#X text 72 78 Links connect masses two by two. They got 4 physicals
+;
+#X text 70 134 the two masses at the creation.;
+#X text 71 120 message. The lenght is initialised to the distance between
+;
+#X text 71 106 Rigidity \, viscosity and damping are defined by the
+creation;
+#X text 409 442 \$2 : Id (symbol) of masses type 1;
+#X text 409 460 \$3 : Id (symbol) of masses type 2;
+#X text 70 148 Interactor links are links between mutiples masses \,
+instead;
+#X text 70 161 of creation number \, the masses linked are defined
+with;
+#X text 69 175 their Id.;
+#X obj 33 821 msd2D;
+#X connect 1 0 56 0;
+#X connect 14 0 56 0;
+#X connect 18 0 56 0;
+#X connect 22 0 56 0;
+#X connect 23 0 56 0;
+#X connect 26 0 56 0;
+#X connect 28 0 56 0;
+#X restore 223 342 pd links;
+#X text 75 312 HELP on masses --->;
+#X text 74 343 HELP on links --->;
+#X text 13 117 There are 4 types of messages for msd :;
+#X text 14 81 It is designed to implement particules physical model
+in PD.The model is based on two elements type : mass and link.;
+#X obj 13 132 cnv 15 420 30 empty empty empty 20 12 0 14 -262131 -66577
+0;
+#X obj 13 165 cnv 15 420 30 empty empty empty 20 12 0 14 -261689 -66577
+0;
+#X obj 13 198 cnv 15 420 30 empty empty empty 20 12 0 14 -262131 -66577
+0;
+#X obj 13 231 cnv 15 420 30 empty empty empty 20 12 0 14 -261689 -66577
+0;
+#X text 16 139 CREATION : To create the model masses and links.;
+#X text 16 204 DYNAMIC SETTING : To set the model parameters dynamically.
+;
+#X text 16 237 ATTRIBUTES : To get the model parameters.;
+#X text 16 166 COMPUTATION : To compute the new model state based on
+previous instant.;
+#X text 94 23 MSD2D : mass - spring - damper model;
+#X text 15 68 MSD2D is the 2D object of the msd objects collection.
+;
diff --git a/msd2D/main.cpp b/msd2D/main.cpp
index 863513c..7872cbf 100755
--- a/msd2D/main.cpp
+++ b/msd2D/main.cpp
@@ -101,6 +101,7 @@ public:
protected:
// --------------------------------------------------------------- RESET
+// ----------------------------------------------------------------------
void m_reset()
{
@@ -121,6 +122,7 @@ protected:
}
// -------------------------------------------------------------- COMPUTE
+// -----------------------------------------------------------------------
void m_bang()
{
@@ -131,57 +133,58 @@ protected:
for (i=0; i<nb_link; i++) {
// compute link forces
distance = sqrt(pow(link[i]->mass1->posX-link[i]->mass2->posX,2) +
- pow(link[i]->mass1->posY-link[i]->mass2->posY,2));
- F = link[i]->K1 * (distance - link[i]->longueur) ; // F = k1(x1-x2)
- F += link[i]->D1 * (distance - link[i]->distance_old) ; // F = F + D1(v1-v2)
+ pow(link[i]->mass1->posY-link[i]->mass2->posY,2)); // L[n] = sqrt( (x1-x2)² +(y1-y2)²)
+ F = link[i]->K1 * (distance - link[i]->longueur) ; // F[n] = k1 (L[n] - L[0])
+ F += link[i]->D1 * (distance - link[i]->distance_old) ; // F[n] = F[n] + D1 (L[n] - L[n-1])
if (distance != 0) {
- Fx = F * (link[i]->mass1->posX - link[i]->mass2->posX)/distance;
- Fy = F * (link[i]->mass1->posY - link[i]->mass2->posY)/distance;
+ Fx = F * (link[i]->mass1->posX - link[i]->mass2->posX)/distance; // Fx = F * Lx[n]/L[n]
+ Fy = F * (link[i]->mass1->posY - link[i]->mass2->posY)/distance; // Fy = F * Ly[n]/L[n]
}
- link[i]->mass1->forceX -= Fx;
- link[i]->mass1->forceX -= link[i]->D2*link[i]->mass1->speedX;
- link[i]->mass2->forceX += Fx;
- link[i]->mass2->forceX -= link[i]->D2*link[i]->mass2->speedX;
- link[i]->mass1->forceY -= Fy;
- link[i]->mass1->forceY -= link[i]->D2*link[i]->mass1->speedY;
- link[i]->mass2->forceY += Fy;
- link[i]->mass2->forceY -= link[i]->D2*link[i]->mass2->speedY;
- link[i]->distance_old = distance;
+ link[i]->mass1->forceX -= Fx; // Fx1[n] = -Fx
+ link[i]->mass1->forceX -= link[i]->D2*link[i]->mass1->speedX; // Fx1[n] = Fx1[n] - D2 * vx1[n-1]
+ link[i]->mass2->forceX += Fx; // Fx2[n] = Fx
+ link[i]->mass2->forceX -= link[i]->D2*link[i]->mass2->speedX; // Fx2[n] = Fx2[n] - D2 * vx2[n-1]
+ link[i]->mass1->forceY -= Fy; // Fy1[n] = -Fy
+ link[i]->mass1->forceY -= link[i]->D2*link[i]->mass1->speedY; // Fy1[n] = Fy1[n] - D2 * vy1[n-1]
+ link[i]->mass2->forceY += Fy; // Fy2[n] = Fy
+ link[i]->mass2->forceY -= link[i]->D2*link[i]->mass2->speedY; // Fy1[n] = Fy1[n] - D2 * vy1[n-1]
+ link[i]->distance_old = distance; // L[n-1] = L[n]
}
for (i=0; i<nb_mass; i++)
// compute new masses position only if mobile = 1
if (mass[i]->mobile == 1) {
- X_new = mass[i]->forceX * mass[i]->invM + 2*mass[i]->posX - mass[i]->posX2;
- mass[i]->posX2 = mass[i]->posX;
- mass[i]->posX = max(min(X_new,Xmax),Xmin); // x = x + v
- mass[i]->speedX = mass[i]->posX - mass[i]->posX2; // v = v + F/M
- Y_new = mass[i]->forceY * mass[i]->invM + 2*mass[i]->posY - mass[i]->posY2;
- mass[i]->posY2 = mass[i]->posY;
- mass[i]->posY = max(min(Y_new,Ymax),Ymin); // x = x + v
- mass[i]->speedY = mass[i]->posY - mass[i]->posY2; // v = v + F/M
+ X_new = mass[i]->forceX * mass[i]->invM + 2*mass[i]->posX - mass[i]->posX2; // x[n] =Fx[n]/M+2x[n]-x[n-1]
+ mass[i]->posX2 = mass[i]->posX; // x[n-2] = x[n-1]
+ mass[i]->posX = max(min(X_new,Xmax),Xmin); // x[n-1] = x[n]
+ mass[i]->speedX = mass[i]->posX - mass[i]->posX2; // vx[n] = x[n] - x[n-1]
+ Y_new = mass[i]->forceY * mass[i]->invM + 2*mass[i]->posY - mass[i]->posY2; // x[n] =Fx[n]/M+2x[n]-x[n-1]
+ mass[i]->posY2 = mass[i]->posY; // x[n-2] = x[n-1]
+ mass[i]->posY = max(min(Y_new,Ymax),Ymin); // x[n-1] = x[n]
+ mass[i]->speedY = mass[i]->posY - mass[i]->posY2; // vx[n] = x[n] - x[n-1]
}
for (i=0; i<nb_mass; i++) {
// clear forces
mass[i]->out_forceX = mass[i]->forceX;
- mass[i]->forceX = 0;
+ mass[i]->forceX = 0; // Fx[n] = 0
mass[i]->out_forceY = mass[i]->forceY;
- mass[i]->forceY = 0;
+ mass[i]->forceY = 0; // Fy[n] = 0
}
}
// -------------------------------------------------------------- MASSES
+// ----------------------------------------------------------------------
void m_mass(int argc,t_atom *argv)
// add a mass
- // Id, nbr, mobile, invM, speedX, posX, forceX
+ // Id, nbr, mobile, invM, speedX Y, posX Y, forceX Y
{
t_atom sortie[6], aux[2];
t_float M;
- mass[nb_mass] = new t_mass; // new pointer
- mass[nb_mass]->Id = GetSymbol(argv[0]); // ID
+ mass[nb_mass] = new t_mass; // new mass
+ mass[nb_mass]->Id = GetSymbol(argv[0]); // ID
mass[nb_mass]->mobile = GetInt(argv[1]); // mobile
if (GetFloat(argv[2])==0)
M=1;
@@ -195,7 +198,7 @@ protected:
mass[nb_mass]->posY = GetFloat(argv[4]); // y[n]
mass[nb_mass]->posY2 = GetFloat(argv[4]); // y[n-1]
mass[nb_mass]->forceY = 0; // Fy[n]
- mass[nb_mass]->nbr = id_mass; // id_nbr
+ mass[nb_mass]->nbr = id_mass; // id number
nb_mass++ ;
id_mass++;
nb_mass = min ( nb_max_mass -1, nb_mass );
@@ -297,6 +300,7 @@ protected:
t_int i,nb_link_delete=0;
t_atom sortie[6], aux[nb_link];
+ // Delete associated links
for (i=0; i<nb_link;i++) {
if (link[i]->mass1->nbr == GetInt(argv[0]) || link[i]->mass2->nbr == GetInt(argv[0])) {
SetFloat((aux[nb_link_delete]),link[i]->nbr);
@@ -307,7 +311,7 @@ protected:
for (i=0; i<nb_link_delete;i++)
m_delete_link(1,&aux[i]);
-
+ // delete mass
for (i=0; i<nb_mass;i++)
if (mass[i]->nbr == GetAInt(argv[0])) {
SetFloat((sortie[0]),mass[i]->nbr);
@@ -327,29 +331,30 @@ protected:
void m_Xmax(int argc,t_atom *argv)
{
- // set damping of link(s) named Id
+ // set X max
Xmax = GetFloat(argv[0]);
}
void m_Ymax(int argc,t_atom *argv)
{
- // set damping of link(s) named Id
+ // set Y max
Ymax = GetFloat(argv[0]);
}
void m_Xmin(int argc,t_atom *argv)
{
- // set damping of link(s) named Id
+ // set X min
Xmin = GetFloat(argv[0]);
}
void m_Ymin(int argc,t_atom *argv)
{
- // set damping of link(s) named Id
+ // set Y min
Ymin = GetFloat(argv[0]);
}
// -------------------------------------------------------------- LINKS
+// ---------------------------------------------------------------------
void m_link(int argc,t_atom *argv)
// add a link
@@ -358,21 +363,21 @@ protected:
t_atom sortie[7], aux[2];
t_int i;
- link[nb_link] = new t_link;
+ link[nb_link] = new t_link; // new link
link[nb_link]->Id = GetSymbol(argv[0]);
for (i=0; i<nb_mass;i++)
- if (mass[i]->nbr==GetAInt(argv[1]))
+ if (mass[i]->nbr==GetAInt(argv[1])) // pointer on mass 1
link[nb_link]->mass1 = mass[i];
- else if(mass[i]->nbr==GetAInt(argv[2]))
+ else if(mass[i]->nbr==GetAInt(argv[2])) // pointer on mass 2
link[nb_link]->mass2 = mass[i];
- link[nb_link]->K1 = GetFloat(argv[3]);
- link[nb_link]->D1 = GetFloat(argv[4]);
- link[nb_link]->D2 = GetFloat(argv[5]);
- link[nb_link]->longx = link[nb_link]->mass1->posX - link[nb_link]->mass2->posX;
- link[nb_link]->longy = link[nb_link]->mass1->posY - link[nb_link]->mass2->posY;
- link[nb_link]->longueur = sqrt( pow(link[nb_link]->longx,2) + pow(link[nb_link]->longy,2));
- link[nb_link]->nbr = id_link;
- link[nb_link]->distance_old = link[nb_link]->longueur;
+ link[nb_link]->K1 = GetFloat(argv[3]); // K1
+ link[nb_link]->D1 = GetFloat(argv[4]); // D1
+ link[nb_link]->D2 = GetFloat(argv[5]); // D2
+ link[nb_link]->longx = link[nb_link]->mass1->posX - link[nb_link]->mass2->posX; // Lx[0]
+ link[nb_link]->longy = link[nb_link]->mass1->posY - link[nb_link]->mass2->posY; // Ly[0]
+ link[nb_link]->longueur = sqrt( pow(link[nb_link]->longx,2) + pow(link[nb_link]->longy,2)); // L[0] = sq( Lx[0]²+Ly[0]²)
+ link[nb_link]->nbr = id_link; // id number
+ link[nb_link]->distance_old = link[nb_link]->longueur;// L[n-1]
nb_link++;
id_link++;
nb_link = min ( nb_max_link -1, nb_link );
@@ -415,7 +420,7 @@ protected:
SetSymbol((arglist[0]),GetSymbol(argv[0]));
SetFloat((arglist[1]),mass[imass1[i]]->nbr);
SetFloat((arglist[2]),mass[imass2[j]]->nbr);
- SetFloat((arglist[3]),GetAInt(argv[3]));
+ SetFloat((arglist[3]),GetFloat(argv[3]));
SetFloat((arglist[4]),GetFloat(argv[4]));
SetFloat((arglist[5]),GetFloat(argv[5]));
m_link(6,arglist);
@@ -437,7 +442,7 @@ protected:
void m_setD(int argc,t_atom *argv)
{
- // set damping of link(s) named Id
+ // set viscosity of link(s) named Id
t_int i;
const t_symbol *sym = GetSymbol(argv[0]);
@@ -477,7 +482,7 @@ protected:
SetFloat((sortie[5]),link[i]->D1);
SetFloat((sortie[6]),link[i]->D2);
delete link[i];
- link[i]=link[nb_link-1];
+ link[i]=link[nb_link-1]; // copy last link instead
nb_link--;
ToOutAnything(1,S_Link_deleted,7,sortie);
break;
@@ -486,7 +491,7 @@ protected:
// -------------------------------------------------------------- GET
-
+// -------------------------------------------------------------------
void m_get(int argc,t_atom *argv)
// get attributes
{
@@ -498,21 +503,21 @@ protected:
if (argc == 1)
{
- if (auxtype == S_massesPos)// get all masses positions
+ if (auxtype == S_massesPos) // get all masses positions
for (i=0; i<nb_mass; i++)
{
SetFloat(sortie[0],mass[i]->posX);
SetFloat(sortie[1],mass[i]->posY);
ToOutAnything(0,S_massesPos,2,sortie);
}
- else if (auxtype == S_massesForces)// get all masses forces
+ else if (auxtype == S_massesForces) // get all masses forces
for (i=0; i<nb_mass; i++)
{
SetFloat(sortie[0],mass[i]->out_forceX);
SetFloat(sortie[1],mass[i]->out_forceY);
ToOutAnything(0,S_massesForces,2,sortie);
}
- else if (auxtype == S_linksPos)// get all links positions
+ else if (auxtype == S_linksPos) // get all links positions
for (i=0; i<nb_link; i++)
{
SetFloat(sortie[0],link[i]->mass1->posX);
@@ -521,7 +526,7 @@ protected:
SetFloat(sortie[3],link[i]->mass2->posY);
ToOutAnything(0,S_linksPos,4,sortie);
}
- else // get all masses speeds
+ else // get all masses speeds
for (i=0; i<nb_mass; i++)
{
SetFloat(sortie[0],mass[i]->speedX);
@@ -529,7 +534,7 @@ protected:
ToOutAnything(0,S_massesSpeeds,2,sortie);
}
}
- else if (auxtype == S_massesPos) // get mass positions
+ else if (auxtype == S_massesPos) // get mass positions
{
if (auxarg == 0) // No
{
@@ -559,7 +564,7 @@ protected:
}
}
}
- else if (auxtype == S_massesForces) // get mass forces
+ else if (auxtype == S_massesForces) // get mass forces
{
if (auxarg == 0) // No
{
@@ -589,7 +594,7 @@ protected:
}
}
}
- else if (auxtype == S_linksPos) // get links positions
+ else if (auxtype == S_linksPos) // get links positions
{
if (auxarg == 0) // No
{
@@ -623,7 +628,7 @@ protected:
}
}
}
- else // get mass speeds
+ else // get mass speeds
{
if (auxarg == 0) // No
{
@@ -671,7 +676,7 @@ protected:
}
void m_force_dumpl()
- // List of masses positions on first outlet
+ // List of masses forces on first outlet
{
t_atom sortie[2*nb_mass];
t_int i;
@@ -684,7 +689,7 @@ protected:
}
void m_info_dumpl()
- // List of masses positions on first outlet
+ // List of infos on masses and links on first outlet
{
t_atom sortie[7];
t_int i;
@@ -713,6 +718,7 @@ protected:
}
// -------------------------------------------------------------- GLOBAL VARIABLES
+// --------------------------------------------------------------------------------
t_link * link[nb_max_link];
t_mass * mass[nb_max_mass];
@@ -720,9 +726,11 @@ protected:
int nb_link, nb_mass, id_mass, id_link;
// -------------------------------------------------------------- SETUP
+// ---------------------------------------------------------------------
private:
+ // static symbols
const static t_symbol *S_Reset;
const static t_symbol *S_Mass;
const static t_symbol *S_Link;
diff --git a/msd3D/filet.pd b/msd3D/filet.pd
index 3a4575b..ccc5fc5 100644
--- a/msd3D/filet.pd
+++ b/msd3D/filet.pd
@@ -20,9 +20,7 @@
#X obj 330 218 + 1;
#X obj 381 153 - 1;
#X obj 387 340 moses;
-#X obj 46 257 * \$3;
#X obj 46 280 + \$1;
-#X obj 176 256 * \$4;
#X obj 176 278 + \$2;
#X obj 46 234 mod \$6;
#X obj 176 234 div \$6;
@@ -43,11 +41,13 @@
#X obj 441 390 f;
#X obj 473 395 + \$6;
#X obj 521 313 - 1;
-#X msg 54 359 mass filet 1 80 \$1 \$2 50;
+#X msg 54 359 mass filet 1 80 \$1 \$2 0;
+#X obj 46 257 * \$3;
+#X obj 176 256 * \$4;
#X connect 1 0 5 0;
-#X connect 1 0 43 0;
+#X connect 1 0 41 0;
#X connect 2 0 5 1;
-#X connect 2 0 28 0;
+#X connect 2 0 26 0;
#X connect 3 0 6 0;
#X connect 4 0 7 0;
#X connect 5 0 4 1;
@@ -60,47 +60,47 @@
#X connect 8 0 10 0;
#X connect 9 0 7 1;
#X connect 9 0 17 1;
-#X connect 10 0 25 0;
-#X connect 10 1 26 0;
-#X connect 11 0 44 0;
+#X connect 10 0 23 0;
+#X connect 10 1 24 0;
+#X connect 11 0 42 0;
#X connect 12 0 15 0;
#X connect 13 0 9 0;
-#X connect 13 0 33 0;
+#X connect 13 0 31 0;
#X connect 14 0 13 0;
#X connect 15 0 16 0;
#X connect 15 1 4 0;
#X connect 16 0 17 0;
#X connect 17 0 18 0;
#X connect 18 0 17 1;
-#X connect 18 0 37 0;
+#X connect 18 0 35 0;
#X connect 19 0 16 1;
-#X connect 20 0 34 0;
-#X connect 21 0 22 0;
-#X connect 22 0 11 0;
-#X connect 23 0 24 0;
-#X connect 24 0 11 1;
-#X connect 25 0 21 0;
-#X connect 26 0 23 0;
-#X connect 28 0 20 1;
-#X connect 29 0 20 0;
-#X connect 30 0 38 0;
-#X connect 31 0 32 1;
-#X connect 32 0 36 0;
-#X connect 33 0 1 0;
-#X connect 33 1 2 0;
-#X connect 34 0 35 0;
-#X connect 35 0 32 0;
-#X connect 36 0 0 0;
-#X connect 37 0 29 0;
-#X connect 37 1 31 0;
-#X connect 37 1 35 1;
-#X connect 37 2 30 0;
-#X connect 37 3 42 0;
-#X connect 37 3 41 1;
-#X connect 38 0 40 0;
-#X connect 39 0 36 0;
-#X connect 40 0 41 0;
-#X connect 41 0 39 0;
-#X connect 42 0 39 1;
-#X connect 43 0 38 1;
-#X connect 44 0 0 0;
+#X connect 20 0 32 0;
+#X connect 21 0 11 0;
+#X connect 22 0 11 1;
+#X connect 23 0 43 0;
+#X connect 24 0 44 0;
+#X connect 26 0 20 1;
+#X connect 27 0 20 0;
+#X connect 28 0 36 0;
+#X connect 29 0 30 1;
+#X connect 30 0 34 0;
+#X connect 31 0 1 0;
+#X connect 31 1 2 0;
+#X connect 32 0 33 0;
+#X connect 33 0 30 0;
+#X connect 34 0 0 0;
+#X connect 35 0 27 0;
+#X connect 35 1 29 0;
+#X connect 35 1 33 1;
+#X connect 35 2 28 0;
+#X connect 35 3 40 0;
+#X connect 35 3 39 1;
+#X connect 36 0 38 0;
+#X connect 37 0 34 0;
+#X connect 38 0 39 0;
+#X connect 39 0 37 0;
+#X connect 40 0 37 1;
+#X connect 41 0 36 1;
+#X connect 42 0 0 0;
+#X connect 43 0 21 0;
+#X connect 44 0 22 0;
diff --git a/msd3D/help-msd3D.pd b/msd3D/help-msd3D.pd
index aa1d899..14fd769 100644
--- a/msd3D/help-msd3D.pd
+++ b/msd3D/help-msd3D.pd
@@ -1,83 +1,176 @@
-#N canvas 0 0 743 844 10;
-#X obj 17 9 cnv 15 610 305 empty empty CREATION 20 12 0 14 -262131
+#N canvas 0 0 467 396 10;
+#N canvas 271 52 742 843 masses 0;
+#X obj 62 154 cnv 15 610 180 empty empty CREATION 20 12 0 14 -262131
-66577 0;
-#X msg 34 38 reset;
-#X text 204 69 Add a mass;
-#X text 290 70 \$1 : Id (symbol);
-#X text 289 90 \$2 : fixed or mobile (0/1);
-#X text 289 108 \$3 : mass;
-#X text 289 146 \$1 : Id (symbol);
-#X text 201 146 Add a link;
-#X text 288 166 \$2 : creation No of mass1;
-#X text 288 184 \$3 : creation No of mass2;
-#X text 287 202 \$4 : rigidity;
-#X text 206 39 Delete all masses and links;
-#X text 287 220 \$5 : viscosity;
-#X text 287 237 \$6 : damping;
-#X obj 17 319 cnv 15 610 60 empty empty COMPUTATION 20 12 0 14 -261689
+#X msg 79 183 reset;
+#X text 249 214 Add a mass;
+#X text 335 215 \$1 : Id (symbol);
+#X text 334 235 \$2 : fixed or mobile (0/1);
+#X text 334 253 \$3 : mass;
+#X text 251 184 Delete all masses and links;
+#X obj 62 338 cnv 15 610 60 empty empty COMPUTATION 20 12 0 14 -261689
-66577 0;
-#X msg 37 348 bang;
-#X text 190 348 Compute new masses positions;
-#X obj 16 383 cnv 15 610 220 empty empty DYNAMIC_SETTING 20 12 0 14
+#X msg 82 367 bang;
+#X text 235 367 Compute new masses positions;
+#X obj 61 403 cnv 15 610 210 empty empty DYNAMIC_SETTING 20 12 0 14
-262131 -66577 0;
-#X msg 124 405 setD \$1 \$2;
-#X text 309 423 \$1 : Id (symbol);
-#X text 309 441 \$2 : New value;
-#X msg 42 405 setK \$1 \$2;
-#X text 305 477 \$1 : Id (symbol);
-#X text 305 495 \$2 : New value;
-#X text 353 532 \$1 : Id (symbol);
-#X text 353 550 \$2 : New value;
-#X msg 42 457 posX \$1 \$2;
-#X text 305 459 Set position of mass(es);
-#X text 352 515 Add force on mass(es);
-#X msg 40 516 forceX \$1 \$2;
-#X msg 210 405 setD2 \$1 \$2;
-#X text 309 405 Set rigidity \, viscosity or damping of link(s);
-#X obj 15 612 cnv 15 610 198 empty empty GET_ATTRIBUTES 20 12 0 14
+#X text 350 449 \$1 : Id (symbol);
+#X text 350 467 \$2 : New value;
+#X text 348 503 \$1 : Id (symbol);
+#X text 348 521 \$2 : New value;
+#X msg 87 429 posX \$1 \$2;
+#X text 350 431 Set position of mass(es);
+#X text 347 486 Add force on mass(es);
+#X msg 82 480 forceX \$1 \$2;
+#X obj 61 617 cnv 15 610 198 empty empty GET_ATTRIBUTES 20 12 0 14
-261689 -66577 0;
-#X msg 101 639 massePosL;
-#X msg 101 667 masseForcesL;
-#X text 202 639 output all masses positions in a list on outlet No
+#X msg 147 644 massePosL;
+#X msg 147 672 masseForcesL;
+#X text 248 644 output all masses positions in a list on outlet No
1;
-#X text 201 668 output all masses forces in a list on outlet No 1;
-#X msg 100 705 get \$1 \$2;
-#X text 203 706 Get specific attribute;
-#X text 203 731 \$1 : Attribute type ( massesPos / massesSpeeds / massesForces
+#X text 247 673 output all masses forces in a list on outlet No 1;
+#X msg 146 710 get \$1 \$2;
+#X text 249 711 Get specific attribute;
+#X text 249 736 \$1 : Attribute type ( massesPos / massesSpeeds / massesForces
/ linksPos );
-#X text 203 768 \$2 : Id (symbol or creations numbers);
-#X msg 31 146 link \$1 \$2 \$3 \$4 \$5 \$6;
-#X msg 30 253 deleteMass \$1;
-#X text 195 255 Delete a mass and associated links;
-#X text 285 272 \$1 : Creation No of mass;
-#X msg 29 289 deleteLink \$1;
-#X text 194 291 Delete a link;
-#X text 295 291 \$1 : Creation No of link;
-#X msg 98 788 infosL;
-#X text 201 788 Get infos on all masses and links on outlet No 2;
-#X text 302 588 \$1 : Value;
-#X msg 135 515 forceY \$1 \$2;
-#X msg 123 457 posY \$1 \$2;
-#X msg 39 568 Xmin \$1 \, Xmax \$1 \, Ymin \$1 \, Ymax \$1;
-#X text 302 571 Set minimimum and maximum of masses positions;
-#X msg 34 69 mass \$1 \$2 \$3 \$4 \$5 \$6;
-#X text 289 126 \$4 \, \$5 \, \$6 : position;
-#X msg 123 457 posY \$1 \$2;
-#X msg 204 457 posZ \$1 \$2;
-#X msg 229 515 forceZ \$1 \$2;
-#X obj -12 816 msd3D;
-#X msg 39 586 Zmin \$1 \, Zmax \$1;
-#X connect 1 0 60 0;
-#X connect 15 0 60 0;
-#X connect 21 0 60 0;
-#X connect 26 0 60 0;
-#X connect 29 0 60 0;
-#X connect 33 0 60 0;
-#X connect 34 0 60 0;
-#X connect 37 0 60 0;
-#X connect 41 0 60 0;
-#X connect 42 0 60 0;
-#X connect 45 0 60 0;
-#X connect 48 0 60 0;
-#X connect 53 0 60 0;
-#X connect 55 0 60 0;
+#X text 249 773 \$2 : Id (symbol or creations numbers);
+#X msg 79 290 deleteMass \$1;
+#X text 248 292 Delete a mass and associated links;
+#X text 338 309 \$1 : Creation No of mass;
+#X msg 144 793 infosL;
+#X text 247 793 Get infos on all masses and links on outlet No 2;
+#X text 347 555 \$1 : Value;
+#X text 73 22 MASSES :;
+#X text 66 69 They got only one physical parameter \, the value of
+their;
+#X text 67 83 mass. They can be mobile or fixed \, in this case forces
+;
+#X text 67 54 The msd masses are the principals objects of the model.
+;
+#X text 66 97 applied on them automatically \, by links \, or manually
+\, by;
+#X text 67 112 messages \, don't do anything.;
+#X msg 81 578 setMobile \$1 \, setFixed \$1;
+#X text 345 578 Change mobile parameter;
+#X text 345 594 \$1 : Creation No of mass;
+#X msg 166 429 posY \$1 \$2;
+#X msg 174 480 forceY \$1 \$2;
+#X text 347 538 Set minimimum and maximum X \, Y of masses;
+#X msg 83 525 Xmin \$1 \, Xmax \$1 \, Ymin \$1 \, Ymax \$1;
+#X msg 79 214 mass \$1 \$2 \$3 \$4 \$5 \$6;
+#X text 334 271 \$4 \, \$5 \, \$6 : initial position;
+#X msg 246 429 posZ \$1 \$2;
+#X msg 83 503 forceZ \$1 \$2;
+#X msg 83 548 Zmin \$1 \, Zmax \$1;
+#X obj 33 821 msd3D;
+#X connect 1 0 52 0;
+#X connect 8 0 52 0;
+#X connect 15 0 52 0;
+#X connect 18 0 52 0;
+#X connect 20 0 52 0;
+#X connect 21 0 52 0;
+#X connect 24 0 52 0;
+#X connect 28 0 52 0;
+#X connect 31 0 52 0;
+#X connect 40 0 52 0;
+#X connect 46 0 52 0;
+#X connect 47 0 52 0;
+#X restore 158 305 pd masses;
+#N canvas 222 83 808 841 links 0;
+#X obj 62 250 cnv 15 610 305 empty empty CREATION 20 12 0 14 -262131
+-66577 0;
+#X msg 79 279 reset;
+#X text 338 308 \$1 : Id (symbol);
+#X text 250 308 Add a link;
+#X text 337 328 \$2 : creation No of mass1;
+#X text 337 346 \$3 : creation No of mass2;
+#X text 336 364 \$4 : rigidity;
+#X text 251 280 Delete all masses and links;
+#X text 336 382 \$5 : viscosity;
+#X text 336 399 \$6 : damping;
+#X obj 61 561 cnv 15 610 82 empty empty DYNAMIC_SETTING 20 12 0 14
+-262131 -66577 0;
+#X msg 172 583 setD \$1 \$2;
+#X text 354 601 \$1 : Id (symbol);
+#X text 354 619 \$2 : New value;
+#X msg 87 583 setK \$1 \$2;
+#X msg 255 583 setD2 \$1 \$2;
+#X text 354 583 Set rigidity \, viscosity or damping of link(s);
+#X obj 60 650 cnv 15 610 140 empty empty GET_ATTRIBUTES 20 12 0 14
+-261689 -66577 0;
+#X msg 75 679 get \$1 \$2;
+#X text 237 680 Get specific attribute;
+#X text 237 705 \$1 : Attribute type ( massesPos / massesSpeeds / massesForces
+/ linksPos );
+#X text 237 742 \$2 : Id (symbol or creations numbers);
+#X msg 78 308 link \$1 \$2 \$3 \$4 \$5 \$6;
+#X msg 74 532 deleteLink \$1;
+#X text 239 534 Delete a link;
+#X text 340 534 \$1 : Creation No of link;
+#X msg 73 762 infosL;
+#X text 236 762 Get infos on all masses and links on outlet No 2;
+#X msg 73 423 iLink \$1 \$2 \$3 \$4 \$5 \$6;
+#X text 338 308 \$1 : Id (symbol);
+#X text 250 308 Add a link;
+#X text 337 328 \$2 : creation No of mass1;
+#X text 337 346 \$3 : creation No of mass2;
+#X text 336 364 \$4 : rigidity;
+#X text 336 382 \$5 : viscosity;
+#X text 336 399 \$6 : damping;
+#X text 410 422 \$1 : Id (symbol);
+#X text 409 478 \$4 : rigidity;
+#X text 409 496 \$5 : viscosity;
+#X text 409 513 \$6 : damping;
+#X text 410 422 \$1 : Id (symbol);
+#X text 409 478 \$4 : rigidity;
+#X text 409 496 \$5 : viscosity;
+#X text 409 513 \$6 : damping;
+#X text 248 423 Add an interactor link;
+#X text 94 52 LINKS :;
+#X text 71 91 parameters : length \, rigidity \, viscosity and damping.
+;
+#X text 72 78 Links connect masses two by two. They got 4 physicals
+;
+#X text 70 134 the two masses at the creation.;
+#X text 71 120 message. The lenght is initialised to the distance between
+;
+#X text 71 106 Rigidity \, viscosity and damping are defined by the
+creation;
+#X text 409 442 \$2 : Id (symbol) of masses type 1;
+#X text 409 460 \$3 : Id (symbol) of masses type 2;
+#X text 70 148 Interactor links are links between mutiples masses \,
+instead;
+#X text 70 161 of creation number \, the masses linked are defined
+with;
+#X text 69 175 their Id.;
+#X obj 33 821 msd3D;
+#X connect 1 0 56 0;
+#X connect 14 0 56 0;
+#X connect 18 0 56 0;
+#X connect 22 0 56 0;
+#X connect 23 0 56 0;
+#X connect 26 0 56 0;
+#X connect 28 0 56 0;
+#X restore 160 335 pd links;
+#X text 12 305 HELP on masses --->;
+#X text 11 336 HELP on links --->;
+#X text -50 110 There are 4 types of messages for msd :;
+#X text -49 74 It is designed to implement particules physical model
+in PD.The model is based on two elements type : mass and link.;
+#X obj -50 125 cnv 15 420 30 empty empty empty 20 12 0 14 -262131 -66577
+0;
+#X obj -50 158 cnv 15 420 30 empty empty empty 20 12 0 14 -261689 -66577
+0;
+#X obj -50 191 cnv 15 420 30 empty empty empty 20 12 0 14 -262131 -66577
+0;
+#X obj -50 224 cnv 15 420 30 empty empty empty 20 12 0 14 -261689 -66577
+0;
+#X text -47 132 CREATION : To create the model masses and links.;
+#X text -47 197 DYNAMIC SETTING : To set the model parameters dynamically.
+;
+#X text -47 230 ATTRIBUTES : To get the model parameters.;
+#X text -47 159 COMPUTATION : To compute the new model state based
+on previous instant.;
+#X text 32 16 MSD3D : mass - spring - damper model;
+#X text -48 61 MSD3D is the 3D object of the msd objects collection.
+;
diff --git a/msd3D/main.cpp b/msd3D/main.cpp
index a8cc727..428a86b 100755
--- a/msd3D/main.cpp
+++ b/msd3D/main.cpp
@@ -106,7 +106,7 @@ public:
protected:
// --------------------------------------------------------------- RESET
-
+// ----------------------------------------------------------------------
void m_reset()
{
t_int i;
@@ -126,7 +126,7 @@ protected:
}
// -------------------------------------------------------------- COMPUTE
-
+// -----------------------------------------------------------------------
void m_bang()
{
t_float F=0,Fx=0,Fy=0, Fz=0,distance,vitesse, X_new, Y_new, Z_new;
@@ -135,44 +135,44 @@ protected:
for (i=0; i<nb_link; i++) {
// compute link forces
- distance = sqrt(pow(link[i]->mass1->posX-link[i]->mass2->posX,2) +
- pow(link[i]->mass1->posY-link[i]->mass2->posY,2) + pow(link[i]->mass1->posZ-link[i]->mass2->posZ,2));
- F = link[i]->K1 * (distance - link[i]->longueur) ; // F = k1(x1-x2)
- F += link[i]->D1 * (distance - link[i]->distance_old) ; // F = F + D1(v1-v2)
+ distance = sqrt(pow(link[i]->mass1->posX-link[i]->mass2->posX,2) + pow(link[i]->mass1->posY
+ -link[i]->mass2->posY,2) + pow(link[i]->mass1->posZ-link[i]->mass2->posZ,2)); // L[n]
+ F = link[i]->K1 * (distance - link[i]->longueur) ; // F = K1(L[n] - L[0])
+ F += link[i]->D1 * (distance - link[i]->distance_old) ; // F = F + D1(L[n] - L[n-1])
if (distance != 0) {
- Fx = F * (link[i]->mass1->posX - link[i]->mass2->posX)/distance;
- Fy = F * (link[i]->mass1->posY - link[i]->mass2->posY)/distance;
- Fz = F * (link[i]->mass1->posZ - link[i]->mass2->posZ)/distance;
+ Fx = F * (link[i]->mass1->posX - link[i]->mass2->posX)/distance; // Fx[n] = F * Lx[n]/L[n]
+ Fy = F * (link[i]->mass1->posY - link[i]->mass2->posY)/distance; // Fy[n] = F * Ly[n]/L[n]
+ Fz = F * (link[i]->mass1->posZ - link[i]->mass2->posZ)/distance; // Fy[n] = F * Lz[n]/L[n]
}
- link[i]->mass1->forceX -= Fx;
- link[i]->mass1->forceX -= link[i]->D2*link[i]->mass1->speedX;
- link[i]->mass2->forceX += Fx;
- link[i]->mass2->forceX -= link[i]->D2*link[i]->mass2->speedX;
- link[i]->mass1->forceY -= Fy;
- link[i]->mass1->forceY -= link[i]->D2*link[i]->mass1->speedY;
- link[i]->mass2->forceY += Fy;
- link[i]->mass2->forceY -= link[i]->D2*link[i]->mass2->speedY;
- link[i]->mass1->forceZ -= Fz;
- link[i]->mass1->forceZ -= link[i]->D2*link[i]->mass1->speedZ;
- link[i]->mass2->forceZ += Fz;
- link[i]->mass2->forceZ -= link[i]->D2*link[i]->mass2->speedZ;
- link[i]->distance_old = distance;
+ link[i]->mass1->forceX -= Fx; // Fx1[n] = -Fx
+ link[i]->mass1->forceX -= link[i]->D2*link[i]->mass1->speedX; // Fx1[n] = Fx1[n] - D2 * vx1[n-1]
+ link[i]->mass2->forceX += Fx; // Fx2[n] = Fx
+ link[i]->mass2->forceX -= link[i]->D2*link[i]->mass2->speedX; // Fx2[n] = Fx2[n] - D2 * vx2[n-1]
+ link[i]->mass1->forceY -= Fy; // Fy1[n] = -Fy
+ link[i]->mass1->forceY -= link[i]->D2*link[i]->mass1->speedY; // Fy1[n] = Fy1[n] - D2 * vy1[n-1]
+ link[i]->mass2->forceY += Fy; // Fy2[n] = Fy
+ link[i]->mass2->forceY -= link[i]->D2*link[i]->mass2->speedY; // Fy2[n] = Fy2[n] - D2 * vy2[n-1]
+ link[i]->mass1->forceZ -= Fz; // Fz1[n] = -Fz
+ link[i]->mass1->forceZ -= link[i]->D2*link[i]->mass1->speedZ; // Fz1[n] = Fz1[n] - D2 * vz1[n-1]
+ link[i]->mass2->forceZ += Fz; // Fz2[n] = Fz
+ link[i]->mass2->forceZ -= link[i]->D2*link[i]->mass2->speedZ; // Fz2[n] = Fz2[n] - D2 * vz2[n-1]
+ link[i]->distance_old = distance; // L[n-1] = L[n]
}
for (i=0; i<nb_mass; i++)
// compute new masses position only if mobile = 1
if (mass[i]->mobile == 1) {
- X_new = mass[i]->forceX * mass[i]->invM + 2*mass[i]->posX - mass[i]->posX2;
- mass[i]->posX2 = mass[i]->posX;
- mass[i]->posX = max(min(X_new,Xmax),Xmin);
+ X_new = mass[i]->forceX * mass[i]->invM + 2*mass[i]->posX - mass[i]->posX2; // x[n] =Fx[n]/M+2x[n]-x[n-1]
+ mass[i]->posX2 = mass[i]->posX; // x[n-2] = x[n-1]
+ mass[i]->posX = max(min(X_new,Xmax),Xmin); // x[n-1] = x[n]
mass[i]->speedX = mass[i]->posX - mass[i]->posX2; // vx[n] = x[n] - x[n-1]
- Y_new = mass[i]->forceY * mass[i]->invM + 2*mass[i]->posY - mass[i]->posY2;
- mass[i]->posY2 = mass[i]->posY;
- mass[i]->posY = max(min(Y_new,Ymax),Ymin);
+ Y_new = mass[i]->forceY * mass[i]->invM + 2*mass[i]->posY - mass[i]->posY2; // y[n] =Fy[n]/M+2y[n]-y[n-1]
+ mass[i]->posY2 = mass[i]->posY; // y[n-2] = y[n-1]
+ mass[i]->posY = max(min(Y_new,Ymax),Ymin); // y[n-1] = y[n]
mass[i]->speedY = mass[i]->posY - mass[i]->posY2; // vy[n] = y[n] - y[n-1]
- Z_new = mass[i]->forceZ * mass[i]->invM + 2*mass[i]->posZ - mass[i]->posZ2;
- mass[i]->posZ2 = mass[i]->posZ;
- mass[i]->posZ = max(min(Z_new,Zmax),Zmin);
+ Z_new = mass[i]->forceZ * mass[i]->invM + 2*mass[i]->posZ - mass[i]->posZ2; // x[n] =Fx[n]/M+2x[n]-x[n-1]
+ mass[i]->posZ2 = mass[i]->posZ; // z[n-2] = z[n-1]
+ mass[i]->posZ = max(min(Z_new,Zmax),Zmin); // z[n-1] = z[n]
mass[i]->speedZ = mass[i]->posZ - mass[i]->posZ2; // vz[n] = z[n] - z[n-1]
}
@@ -188,7 +188,7 @@ protected:
}
// -------------------------------------------------------------- MASSES
-
+// ----------------------------------------------------------------------
void m_mass(int argc,t_atom *argv)
// add a mass
// Id, nbr, mobile, invM, speedX, posX, forceX
@@ -196,26 +196,26 @@ protected:
t_atom sortie[7], aux[2];
t_float M;
- mass[nb_mass] = new t_mass; // new pointer
- mass[nb_mass]->Id = GetSymbol(argv[0]); // Id
+ mass[nb_mass] = new t_mass; // new mass
+ mass[nb_mass]->Id = GetSymbol(argv[0]); // Id
mass[nb_mass]->mobile = GetInt(argv[1]); // mobile
if (GetFloat(argv[2])==0)
M=1;
else M = GetFloat(argv[2]);
- mass[nb_mass]->invM = 1/(M); // invM
+ mass[nb_mass]->invM = 1/(M); // 1/M
mass[nb_mass]->speedX = 0; // vx[n]
- mass[nb_mass]->posX = GetFloat(argv[3]); // x(n]
+ mass[nb_mass]->posX = GetFloat(argv[3]); // x[n]
mass[nb_mass]->posX2 = GetFloat(argv[3]); // x[n-1]
mass[nb_mass]->forceX = 0; // Fx[n]
mass[nb_mass]->speedY = 0; // vy[n]
- mass[nb_mass]->posY = GetFloat(argv[4]); // y[n]
+ mass[nb_mass]->posY = GetFloat(argv[4]); // y[n]
mass[nb_mass]->posY2 = GetFloat(argv[4]); // y[n-1]
mass[nb_mass]->forceY = 0; // Fz[n]
mass[nb_mass]->speedZ = 0; // vz[n]
- mass[nb_mass]->posZ = GetFloat(argv[5]); // z[n]
+ mass[nb_mass]->posZ = GetFloat(argv[5]); // z[n]
mass[nb_mass]->posZ2 = GetFloat(argv[5]); // z[n-1]
mass[nb_mass]->forceZ = 0; // Fz[n]
- mass[nb_mass]->nbr = id_mass; // id_nbr
+ mass[nb_mass]->nbr = id_mass; // id number
nb_mass++ ;
id_mass++;
nb_mass = min ( nb_max_mass -1, nb_mass );
@@ -346,6 +346,7 @@ protected:
t_int i,nb_link_delete=0;
t_atom sortie[7], aux[nb_link];
+ // Delete associated links
for (i=0; i<nb_link;i++) {
if (link[i]->mass1->nbr == GetInt(argv[0]) || link[i]->mass2->nbr == GetInt(argv[0])) {
SetFloat((aux[nb_link_delete]),link[i]->nbr);
@@ -356,7 +357,7 @@ protected:
for (i=0; i<nb_link_delete;i++)
m_delete_link(1,&aux[i]);
-
+ // Delete mass
for (i=0; i<nb_mass;i++)
if (mass[i]->nbr == GetInt(argv[0])) {
SetFloat((sortie[0]),mass[i]->nbr);
@@ -367,7 +368,7 @@ protected:
SetFloat((sortie[5]),mass[i]->posY);
SetFloat((sortie[6]),mass[i]->posZ);
delete mass[i];
- mass[i] = mass[nb_mass-1];
+ mass[i] = mass[nb_mass-1]; // copy last mass indeed
nb_mass--;
ToOutAnything(1,S_Mass_deleted,7,sortie);
break;
@@ -410,8 +411,9 @@ protected:
// set minimum Z of all masses
Zmin = GetFloat(argv[0]);
}
-// -------------------------------------------------------------- LINKS
+// -------------------------------------------------------------- LINKS
+// ---------------------------------------------------------------------
void m_link(int argc,t_atom *argv)
// add a link
// Id, nbr, *mass1, *mass2, K1, D1
@@ -419,21 +421,21 @@ protected:
t_atom sortie[7], aux[2];
t_int i;
- link[nb_link] = new t_link;
- link[nb_link]->Id = GetSymbol(argv[0]);
+ link[nb_link] = new t_link; // new link
+ link[nb_link]->Id = GetSymbol(argv[0]); // ID
for (i=0; i<nb_mass;i++)
- if (mass[i]->nbr==GetInt(argv[1]))
+ if (mass[i]->nbr==GetInt(argv[1])) // pointer on mass 1
link[nb_link]->mass1 = mass[i];
- else if(mass[i]->nbr==GetInt(argv[2]))
+ else if(mass[i]->nbr==GetInt(argv[2])) // pointer on mass 2
link[nb_link]->mass2 = mass[i];
- link[nb_link]->K1 = GetFloat(argv[3]);
- link[nb_link]->D1 = GetFloat(argv[4]);
- link[nb_link]->D2 = GetFloat(argv[5]);
- link[nb_link]->longx = link[nb_link]->mass1->posX - link[nb_link]->mass2->posX;
- link[nb_link]->longy = link[nb_link]->mass1->posY - link[nb_link]->mass2->posY;
- link[nb_link]->longz = link[nb_link]->mass1->posZ - link[nb_link]->mass2->posZ;
+ link[nb_link]->K1 = GetFloat(argv[3]); // K1
+ link[nb_link]->D1 = GetFloat(argv[4]); // D1
+ link[nb_link]->D2 = GetFloat(argv[5]); // D2
+ link[nb_link]->longx = link[nb_link]->mass1->posX - link[nb_link]->mass2->posX; // Lx[0]
+ link[nb_link]->longy = link[nb_link]->mass1->posY - link[nb_link]->mass2->posY; // Ly[0]
+ link[nb_link]->longz = link[nb_link]->mass1->posZ - link[nb_link]->mass2->posZ; // Lz[0]
link[nb_link]->longueur = sqrt( pow(link[nb_link]->longx,2) + pow(link[nb_link]->longy,2) + pow(link[nb_link]->longz,2));
- link[nb_link]->nbr = id_link;
+ link[nb_link]->nbr = id_link; // id number
link[nb_link]->distance_old = link[nb_link]->longueur;
nb_link++;
id_link++;
@@ -500,7 +502,7 @@ protected:
void m_setD(int argc,t_atom *argv)
{
- // set damping of link(s) named Id
+ // set viscosity of link(s) named Id
t_int i;
const t_symbol *sym = GetSymbol(argv[0]);
@@ -540,16 +542,15 @@ protected:
SetFloat((sortie[5]),link[i]->D1);
SetFloat((sortie[6]),link[i]->D2);
delete link[i];
- link[i]=link[nb_link-1];
+ link[i]=link[nb_link-1]; // copy last link
nb_link--;
ToOutAnything(1,S_Link_deleted,7,sortie);
break;
}
}
-
// -------------------------------------------------------------- GET
-
+// -------------------------------------------------------------------
void m_get(int argc,t_atom *argv)
// get attributes
{
@@ -794,16 +795,17 @@ protected:
}
// -------------------------------------------------------------- GLOBAL VARIABLES
-
+// --------------------------------------------------------------------------------
t_link * link[nb_max_link];
t_mass * mass[nb_max_mass];
t_float Xmin, Xmax, Ymin, Ymax, Zmin, Zmax;
int nb_link, nb_mass, id_mass, id_link;
// -------------------------------------------------------------- SETUP
-
+// ---------------------------------------------------------------------
private:
+ // static symbols
const static t_symbol *S_Reset;
const static t_symbol *S_Mass;
const static t_symbol *S_Link;