Created
May 11, 2021 11:36
-
-
Save geoffreygarrett/8dc9d14df3ca6caf6fccffb983639003 to your computer and use it in GitHub Desktop.
cpp-philosophy-1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// -------------------------------------------------------- | |
// Both are the same functions, with two different designs. | |
// -------------------------------------------------------- | |
//! Compute gravitational acceleration. | |
/** | |
* | |
* @param GM gravitational parameter of body exerting acceleration | |
* @param r1 position of body exerting acceleration | |
* @param r2 position of body subject acceleration | |
* | |
* @return acceleration exerted on second body | |
*/ | |
Eigen::Vector3d pointMassAcceleration( | |
const double GM, | |
const Eigen::Vector3d& r1 | |
const Eigen::Vector3d& r2) | |
{ | |
// d: distance between bodies | |
double d = ( r2 - r1 ).norm( ); | |
return - G * ( r2 - r1 ) / ( d * d * d ); | |
} | |
// -------------------------------------------------------- | |
//! Compute gravitational acceleration. | |
Eigen::Vector3d computeGravitationalAcceleration( | |
const Eigen::Vector3d& positionOfBodySubjectToAcceleration, | |
const double gravitationalParameterOfBodyExertingAcceleration, | |
const Eigen::Vector3d& positionOfBodyExertingAcceleration ) | |
{ | |
double distance = ( positionOfBodySubjectToAcceleration - positionOfBodyExertingAcceleration ).norm( ); | |
return -gravitationalParameterOfBodyExertingAcceleration | |
* ( positionOfBodySubjectToAcceleration - positionOfBodyExertingAcceleration ) | |
/ ( distance * distance * distance ); | |
} | |
// -------------------------------------------------------- | |
// | |
// Points to consider: | |
// - readability | |
// - maintainability | |
// - intuitiveness |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment