/* Objecte */
var Net, net; // Object Gradientenfunktion
var Mode, mode; // p_button: Auswahl Aufhängung
var Node = [], node; // Netzknoten, Resultat
/* Variablendeklaration */
var K = 10, k; // Anzahl der vert. Glieder, Index
var N = 10, n; // Anzahl der horiz. Glieder, Index
var x = []; // Koordinaten der Knoten
var y = [];
var vx = []; // Geschwindigk.komp. der Knoten
var vy = [];
var vx_ = []; // Zwischenschritt Geschwindigk.komp. der Knoten
var vy_ = [];
...
function setup()
{
...
Net = new GradientFunctions(); // Gradientenfunktionen der Netzknoten
...
}
function draw()
{
...
for (i = 0; i < I; i++) // leapfrog - Algorithmus
{ // I Iterationen je Stützstelle
for (n = 1; n < N+1; n++)
{
for (k = 1; k < K+1; k++)
{ // alle 1. Integrationen
//if (k == K) console.log("X vor "+x[k][n]+" "+y[k][n]+" "+x[k][n+1]+" "+vy[2][2]);
// k, n, vx, vy, xl, xp, x, xn, xr, yl, yp, y, yn, yr
net = Net.f1(k, n, vx[k][n], vy[k][n], x[k][n-1], x[k-1][n], x[k][n], x[k+1][n], x[k][n+1], y[k][n-1], y[k-1][n], y[k][n], y[k+1][n], y[k][n+1]); // k-ter Knoten
vx_[k][n] = vx[k][n] + net[0]*dt/2;
vy_[k][n] = vy[k][n] + net[1]*dt/2;
//if (k == K) console.log("V_ vor "+vx_[k][n]+" "+vy_[k][n]+" "+net[0]+" "+net[1]);
}
}
for (n = 1; n < N+1; n++)
{
for (k = 1; k < K+1; k++)
{ // alle 2. Integrationen
net = Net.f2(i, k, n, vx_[k][n], vy_[k][n]); // i-te Iteration, k-ter Knoten
x[k][n] = x[k][n] + net[0]*dt;
y[k][n] = y[k][n] + net[1]*dt;
//if (k == K) console.log("nach: "+x[k][n]+" "+y[k][n]+" "+x[k][n+1]+" "+vy[2][2]);
if (k == kActive && n == nActive)
{
vx_[k][n] = 0;
vy_[k][n] = 0;
}
}
}
for (n = 1; n < N+1; n++)
{
for (k = 1; k < K+1; k++)
{ // alle 1. Integrationen
net = Net.f1(k, n, vx[k][n], vy[k][n], x[k][n-1], x[k-1][n], x[k][n], x[k+1][n], x[k][n+1], y[k][n-1], y[k-1][n], y[k][n], y[k+1][n], y[k][n+1]); // k-ter Knoten
vx[k][n] = vx_[k][n] + net[0]*dt/2;
vy[k][n] = vy_[k][n] + net[1]*dt/2;
}
}
}
...
}
function GradientFunctions()
{
var lp, ln; // aktuelle Federlängen: previous to current node, current to next node
var ll, lr; // aktuelle Federlängen: left to current node, current to right node
var ax, ay; // Beschleunigungskomp. am Knoten
var f1x, f1y; // Gradientenfunktionen Beschleunigung in x- bzw. y-Richtung
var f2x, f2y; // Gradientenfunktionen Geschwindigkeit in x- bzw. y-Richtung
/* Methoden */
this.f1 = function( k, n, vx, vy, xl, xp, x, xn, xr, yl, yp, y, yn, yr)
{ // Gradientenfunktion Beschleunigung
if (!(k == kActive && n == nActive))
{
//console.log(k+","+n+": "+place[k][n]+" ");
lp = sqrt(sq(y-yp) + sq(x-xp)); // Momentanfederanlänge vorheriger -> aktueller Knoten
ll = sqrt(sq(y-yl) + sq(x-xl)); // Momentanfederanlänge linker -> aktueller Knoten
ln = sqrt(sq(yn-y) + sq(xn-x)); // Momentanfederanlänge aktueller -> nächster Knoten
lr = sqrt(sq(yr-y) + sq(xr-x)); // Momentanfederanlänge aktueller -> rechter Knoten
/*if (k == 10 || n == 10)
{
console.log("k: "+k+" n: "+n+" Property: "+place[k][n]+" om: "+sqOmega+" d: "+d0);
console.log("inner: y, yp, x, xp "+y+" "+yn+" "+x+" "+xn);
console.log("inner: lp, ll, ln, lr "+lp+" "+ll+" "+ln+" "+lr+" ");
}*/
switch (place[k][n])
{
case 'f': f1x = 0;
f1y = 0;
break;
case 'm': ay = sqOmega*((ln-l0)*(yn-y)/ln + (lr-l0)*(yr-y)/lr - (lp-l0)*(y-yp)/lp - (ll-l0)*(y-yl)/ll); // mittlerer Knoten
ax = sqOmega*((ln-l0)*(xn-x)/ln + (lr-l0)*(xr-x)/lr - (lp-l0)*(x-xp)/lp - (ll-l0)*(x-xl)/ll) + windStrength*aw[n+cycle];
f1x = (ax - 2*d0*vx);
f1y = (g + ay - 2*d0*vy);
break;
case 't': ay = sqOmega*((ln-l0)*(yn-y)/ln + (lr-l0)*(yr-y)/lr - (ll-l0)*(y-yl)/ll); // obere Endzeile
ax = sqOmega*((ln-l0)*(xn-x)/ln + (lr-l0)*(xr-x)/lr - (ll-l0)*(x-xl)/ll) + windStrength*aw[n+cycle];
f1x = (ax - 2*d0*vx);
f1y = (g + ay - 2*d0*vy);
break;
case 'b': ay = sqOmega*((lr-l0)*(yr-y)/lr - (lp-l0)*(y-yp)/lp - (ll-l0)*(y-yl)/ll); // untere Endzeile
ax = sqOmega*((lr-l0)*(xr-x)/lr - (lp-l0)*(x-xp)/lp - (ll-l0)*(x-xl)/ll) + windStrength*aw[n+cycle];
f1x = (ax - 2*d0*vx);
f1y = (g + ay - 2*d0*vy);
break;
case 'l': ay = sqOmega*((ln-l0)*(yn-y)/ln + (lr-l0)*(yr-y)/lr - (lp-l0)*(y-yp)/lp); // linke Endzeile
ax = sqOmega*((ln-l0)*(xn-x)/ln + (lr-l0)*(xr-x)/lr - (lp-l0)*(x-xp)/lp) + windStrength*aw[n+cycle];
f1x = (ax - 2*d0*vx);
f1y = (g + ay - 2*d0*vy);
break;
case 'r': ay = sqOmega*((ln-l0)*(yn-y)/ln - (lp-l0)*(y-yp)/lp - (ll-l0)*(y-yl)/ll); // rechte Endzeile
ax = sqOmega*((ln-l0)*(xn-x)/ln - (lp-l0)*(x-xp)/lp - (ll-l0)*(x-xl)/ll) + windStrength*aw[n+cycle];
f1x = (ax - 2*d0*vx);
f1y = (g + ay - 2*d0*vy);
break;
case '1': ay = sqOmega*((ln-l0)*(yn-y)/ln + (lr-l0)*(yr-y)/lr); // Eckknoten links oben
ax = sqOmega*((ln-l0)*(xn-x)/ln + (lr-l0)*(xr-x)/lr) + windStrength*aw[n+cycle];
f1x = (ax - 2*d0*vx);
f1y = (g + ay - 2*d0*vy);
break;
case '2': ay = sqOmega*((ln-l0)*(yn-y)/ln - (ll-l0)*(y-yl)/ll); // Eckknoten rechts oben
ax = sqOmega*((ln-l0)*(xn-x)/ln - (ll-l0)*(x-xl)/ll) + windStrength*aw[n+cycle];
f1x = (ax - 2*d0*vx);
f1y = (g + ay - 2*d0*vy);
break;
case '3': ay = -sqOmega*((lp-l0)*(y-yp)/lp + (ll-l0)*(y-yl)/ll); // Eckknoten rechts unten
ax = -sqOmega*((lp-l0)*(x-xp)/lp + (ll-l0)*(x-xl)/ll) + windStrength*aw[n+cycle];
f1x = (ax - 2*d0*vx);
f1y = (g + ay - 2*d0*vy);
break;
case '4': ay = sqOmega*((lr-l0)*(yr-y)/lr - (lp-l0)*(y-yp)/lp); // Eckknoten links unten
ax = sqOmega*((lr-l0)*(xr-x)/lr - (lp-l0)*(x-xp)/lp) + windStrength*aw[n+cycle];
f1x = (ax - 2*d0*vx);
f1y = (g + ay - 2*d0*vy);
break;
default: f1x = 0;
f1y = 0;
break;
}
}
else
{
f1x = 0;
f1y = 0;
}
return[f1x, f1y];
}
this.f2 = function( i, k, n, vx, vy)
{ //Gradientenfunktion Geschwindigkeit
if (!(k == kActive && n == nActive))
{
f2x = vx;
f2y = vy;
}
else
{ // k-ten Knoten mit Maus festhalten
f2x = 0;
f2y = 0;
if (i == I-1)
{
kActive = -1;
nActive = -1;
}
}
return[f2x, f2y];
}
}