Refactored for AB5

This commit is contained in:
2022-05-06 22:42:28 +02:00
parent e84bf3bf4a
commit 6b1f1ecc2a
6 changed files with 176 additions and 199 deletions

View File

@@ -1,64 +1,73 @@
// Represents a coherent mass with a mass center in 3D space. Has two naming schemes for its
// methods. Please, do not change this interface definition!
//
/**
* Represents a coherent mass with a mass center in 3D space. Has two naming schemes for its
* methods. Please, do not change this interface definition!
*/
public interface Massive extends Drawable {
// Returns the mass.
/**
* Returns the mass.
*/
default double mass() {
return getMass();
}
// Returns the mass center.
/**
* Returns the mass center.
*/
default Vector3 massCenter() {
return getMassCenter();
}
// Returns the mass.
/**
* Returns the mass.
*/
default double getMass() {
return mass();
}
// Returns the mass center.
/**
* Returns the mass center.
*/
default Vector3 getMassCenter() {
return massCenter();
}
// Returns the approximate radius of 'this', assuming it is a coherent round mass.
// (It is assumed that the radius r is related to the mass m by r = m ^ 0.5,
// where m and r measured in solar units.)
/**
* Returns the approximate radius of 'this', assuming it is a coherent round mass.
* (It is assumed that the radius r is related to the mass m by r = m ^ 0.5,
* where m and r measured in solar units.)
*/
default double getRadius() {
return radius();
}
// Returns the approximate radius of 'this', assuming it is a coherent round mass.
// (It is assumed that the radius r is related to the mass m by r = m ^ 0.5,
// where m and r measured in solar units.)
/**
* Returns the approximate radius of 'this', assuming it is a coherent round mass.
* (It is assumed that the radius r is related to the mass m by r = m ^ 0.5,
* where m and r measured in solar units.)
*/
default double radius() {
return SpaceDraw.massToRadius(mass());
}
// Returns a vector representing the gravitational force exerted by 'b' on this mass.
// The gravitational Force F is calculated by F = G*(m1*m2)/(r*r), with m1 and m2 being the
// masses of the objects interacting, r being the distance between the centers of the masses
// and G being the gravitational constant.
/**
* Returns a vector representing the gravitational force exerted by 'b' on this mass.
* The gravitational Force F is calculated by F = G*(m1*m2)/(r*r), with m1 and m2 being the
* masses of the objects interacting, r being the distance between the centers of the masses
* and G being the gravitational constant.
*/
default Vector3 gravitationalForce(Massive b) {
Vector3 direction = b.massCenter().minus(this.massCenter());
double distance = direction.length();
direction.normalize();
double force = Simulation.G*this.mass()*b.mass()/(distance * distance);
double force = Simulation.G * this.mass() * b.mass() / (distance * distance);
return direction.times(force);
}
// Centers this mass at a new position, according to the specified force vector 'force' exerted
// on it, and updates the current velocity vector accordingly.
// (Velocity depends on the mass of 'this', its current velocity and the exerted force.)
/**
* Centers this mass at a new position, according to the specified force vector 'force' exerted
* on it, and updates the current velocity vector accordingly.
* (Velocity depends on the mass of 'this', its current velocity and the exerted force.)
*/
void move(Vector3 force);
}