As a proof of concept, write a method that computes the acceleration due to gravity from one other body, using Newtonian mechanics and SI units.
The function should take the following parameters:
displacement (3D vector): represents the displacement of object 2 from object 1
m2 (floating point number): represents the mass of object 2
The function should return a 3D vector representing the acceleration of object 1 in response to the gravitational field of object 2.
Using Newton's formula, that should be: 6.6743e-11 * m2 * displacement / |dispacement|^3, where |displacement| is the magnitude of the displacement vector.
In C#, I'm using double for floating-point numbers; I think the equivalent in Rust is f64. After a bit of research, I think a good data type for the vectors will be vector3<f64> from cgmath. It should hopefully perform better than the MathNet.Numerics.LinearAlgebra.Vector<double> that I'm currently using.
As a proof of concept, write a method that computes the acceleration due to gravity from one other body, using Newtonian mechanics and SI units.
The function should take the following parameters:
The function should return a 3D vector representing the acceleration of object 1 in response to the gravitational field of object 2.
Using Newton's formula, that should be:
6.6743e-11 * m2 * displacement / |dispacement|^3
, where|displacement|
is the magnitude of the displacement vector.In C#, I'm using
double
for floating-point numbers; I think the equivalent in Rust isf64
. After a bit of research, I think a good data type for the vectors will bevector3<f64>
fromcgmath
. It should hopefully perform better than theMathNet.Numerics.LinearAlgebra.Vector<double>
that I'm currently using.For reference, this functionality is currently handled in C# by
Body.AddAccelerationOn1DueTo2
andBody.ComputeGravitationalAcceleration
: https://github.com/hypehuman/Mechanics/blob/1ce7c818c21c5d9e2ecdd29e74fe430dc7079e47/MechanicsCore/Body.cs#L62-L65 https://github.com/hypehuman/Mechanics/blob/1ce7c818c21c5d9e2ecdd29e74fe430dc7079e47/MechanicsCore/Body.cs#L94-L101