Skip to content

Instantly share code, notes, and snippets.

@patricoferris
Created August 11, 2018 09:28
Show Gist options
  • Save patricoferris/836d914a253292000dbc3f1e0403ea4b to your computer and use it in GitHub Desktop.
Save patricoferris/836d914a253292000dbc3f1e0403ea4b to your computer and use it in GitHub Desktop.
function centripetalForce(satellite, centre) {
//Get the direction of the force
let force = p5.Vector.sub(centre, satellite.position).normalize();
//Get the distance to centre of rotation from our satellite
let radius = p5.Vector.sub(centre, satellite.position).mag();
//The velocity squared
let velocitySquared = p5.Vector.dot(satellite.velocity, satellite.velocity);
//Pull it all together with the f = (m * v^2) / r equation
force.mult(velocitySquared);
force.mult(satellite.mass);
force.mult(1/radius);
return force;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment