Java Reference
In-Depth Information
...
calculation section of
startRunning()
...
float[] data
=
new float[6];
float[] new
-
indata
=
new float[6];
if (time
<=
fMaxTime)
{
try
{
Thread.sleep (100);
}
catch (InterruptedException ie) {/*ignore*/}
// Continue with calculations
...
data[0] = time;
// position x = A*sin (omega*t)
data[1] = fAmplitude * (float) Math.sin (fOmega * time);
// velocity v = omega*A*cos(omega*t)
data[2] = fOmega * fAmp * (float) Math.cos (fOmega *
time);
// acceleration =-omega**2*A*sin(omega*t)
// =-omega**2 * x
data[3] =-fOmega * fOmega * data[1];
// kinetic energy = 1/2*m*v**2
data[4] =.5f * fMass * data[2] * data[2];
// potential energy = 1/2*k*x**2
data[5]
=
.5f * fSpringCons * data[1] * data[1];
new
-
indata
=
fSimData.storeData (data);
// Obtain new amplitude, omega, and spring constant
// values
fAmplitude
=
new
-
indata[0];
fOmega
=
new
-
indata[1];
fSpringCons
=
new
-
indata[2];
// new
-
indata[3] and new
-
indata[4] are ignored
if ((int)new
-
indata[5] == 1) halt ();
}
else {
// Set time negative indicating that the loop has
// finished
data[0] =-1.0f;
fSimData.storeData (data);
// Break out of the while loop
break;
}
Here we have set the time negative when the loop has finished as a signal to the
client that the simulation has completed normally.
Search WWH ::
Custom Search