hypehuman / Mechanics

0 stars 0 forks source link

Write Rust method to compute gravitational acceleration from a single object #2

Closed hypehuman closed 1 year ago

hypehuman commented 1 year ago

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 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.

For reference, this functionality is currently handled in C# by Body.AddAccelerationOn1DueTo2 and Body.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

hypehuman commented 1 year ago

@NeoScripter finished this at a1365c4a6f60e97d88434516d814c354ff90e43f.