Skip to content

Commit

Permalink
orbital period and acceleration v1
Browse files Browse the repository at this point in the history
  • Loading branch information
SamH1608 committed May 20, 2021
1 parent da71ca4 commit fddf4d4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
11 changes: 10 additions & 1 deletion app/src/main/java/src/univ/CelestialBody.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,20 @@ public double orbitalVelocity(double r2)
return Math.sqrt((G*mass)/r);

}
public double acceleration()
/**
* Calculates the gravitational acceleration of a planet
* @return acceleration in m/s^2
*/
public double planetaryGravitationalAcceleration()
{
double G = 6.67408e-11;
return (G*mass)/(radius*radius);
}
/**
* Calculates the orbital period of a planet
* @param r2 The height of the orbit above the planet's surface (meters)
* @return time (seconds) it takes for an object to orbit once around another object
*/
public double orbitalPeriod(double r2)
{
double G = 6.67408e-11;
Expand Down
6 changes: 2 additions & 4 deletions app/src/test/java/src/test/TestCelestialBody.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,14 @@ void testOrbitalVelocity()
}
/* Tests that the acceleration() method calculates the gravitational acceleration of the earth correctly*/
@Test
void testAcceleration()
void testPlanetaryGravitationalAcceleration()
{
/*Earth's gravitational acceleration*/
double exactAcceleration = 9.8;

/*Test*/
CelestialBody earth = new CelestialBody(new Vector3d(), new Vector3d(), 5.97*Math.pow(10,24), 6378000, "Earth", "", "", LocalDateTime.of(d1, t1));
double testAcceleration = earth.acceleration();
System.out.println(testAcceleration);
double testAcceleration = earth.planetaryGravitationalAcceleration();
assertTrue(inRange(exactAcceleration, testAcceleration, epsilon));
}
/* Tests that the orbitalPeriodMethod() method calculates the orbital period of the earth around the sun correctly*/
Expand All @@ -162,7 +161,6 @@ void testOrbitalPeriod()

/*Test*/
double testOrbitalPeriod = sun.orbitalPeriod(r2);
System.out.println(testOrbitalPeriod);
assertTrue(inRange(exactOrbitalPeriod, testOrbitalPeriod, epsilon));
}
/**
Expand Down

0 comments on commit fddf4d4

Please sign in to comment.