Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions .gitignore

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,38 @@
* Represents a pendulum
*/
public abstract class AbstractPendulum {



/* instance variables - string length, point mass, angular displacement
* at t=0, constant for local gravitational field in m/s^2 (e.g., 9.81 on Earth)
*/
public static double gravity = 9.80665;
private double stringLength, pointMass;
protected double theta0;
protected double g;
public interface gravityInter {
public static void GravityConstant(double gra) {
gravity = gra;
}
public static double getGravitationalField() {
return gravity;
}
}

/**
* Creates a new Pendulum instance using
* inLength: the string length (>0)
* inMass: the point mass (>0)
* inTheta0: angular displacement at t=0 (0<=theta0)
* inG: gravitational field value to use
* GRAVITY: Always the gravitational field value to use from now on. Replaces inG.
*/
public AbstractPendulum (double inLength, double inMass, double inTheta0, double inG) {
public AbstractPendulum (double inLength, double inMass, double inTheta0) {
if (validStringLength (inLength)) stringLength = inLength;
else throw new IllegalArgumentException ("invalid string length: " + inLength);
if (validPointMass(inMass)) pointMass = inMass;
else throw new IllegalArgumentException ("invalid point mass: " + inMass);
if (validDisplacement (inTheta0)) theta0 = inTheta0;
else throw new IllegalArgumentException
("invalid angular displacement: " + inTheta0);
if (validGC (inG)) g = inG;
else throw new IllegalArgumentException ("invalid local gravitational field: " + inG);
else throw new IllegalArgumentException ("invalid angular displacement: " + inTheta0);
if (validGC (gravity)) gravityInter.getGravitationalField();
else throw new IllegalArgumentException ("invalid local gravitational field: " + gravity);
}

private boolean validDisplacement (double val) { return (val >= 0); }
Expand All @@ -42,7 +48,6 @@ public AbstractPendulum (double inLength, double inMass, double inTheta0, double
public double getPointMass () { return pointMass; }

public double getStringLength () { return stringLength; }

public double getGravitationalField () { return g; }


public double grav = gravityInter.getGravitationalField();//get the grav number in the gravityInter
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.text.NumberFormat;

/**
*
* compares the values of a simple pendulum using the harmonic motion equation
* versus the Euler algorithm approximation
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dal.gravity;

/**
*
* Represents a pendulum
*/
public class RegularPendulum extends AbstractEarthPendulum {
Expand All @@ -18,7 +19,7 @@ public RegularPendulum (double inLength, double inMass, double inTheta0,
dissipation = inDiss;
lastVel = 0;
lastTheta = this.getMaxAngularDisplacement ();
lastAccel = -(this.getGravitationalField () / this.getStringLength ())*Math.sin (lastTheta);
lastAccel = -(grav/ this.getStringLength ())*Math.sin (lastTheta);
}

public RegularPendulum (double inLength, double inMass, double inTheta0,
Expand All @@ -30,7 +31,7 @@ public void step () {
iterations++;
lastTheta = lastTheta + lastVel*delta;
lastVel = lastVel + lastAccel*delta;
lastAccel = - dissipation*lastVel - this.getGravitationalField () / this.getStringLength () * Math.sin (lastTheta);
lastAccel = - dissipation*lastVel - grav/ this.getStringLength () * Math.sin (lastTheta);
}

public double getLastTheta () { return lastTheta; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dal.gravity;

/**
*
* Represents pendulums exhibiting (approximately) simple harmonic motion
*/
public class SimplePendulum extends AbstractEarthPendulum {
Expand All @@ -15,9 +16,9 @@ public class SimplePendulum extends AbstractEarthPendulum {
*/
public SimplePendulum (double inLength, double inMass, double inTheta0) {
super (inLength, inMass, inTheta0);
angularFrequency = Math.sqrt (this.getGravitationalField () / this.getStringLength ());
angularFrequency = Math.sqrt (grav/ this.getStringLength ());
periodOfMotion = 2 * Math.PI
* Math.sqrt (this.getStringLength () / this.getGravitationalField ());
* Math.sqrt (this.getStringLength () / grav);
}

/**
Expand Down
23 changes: 0 additions & 23 deletions src/main/java/dal/gravity/AbstractEarthPendulum.java

This file was deleted.