Skip to content

Instantly share code, notes, and snippets.

@Sascha-T
Created March 29, 2019 18:04
Show Gist options
  • Save Sascha-T/8a169d09bca5218b985a958bcb089148 to your computer and use it in GitHub Desktop.
Save Sascha-T/8a169d09bca5218b985a958bcb089148 to your computer and use it in GitHub Desktop.
let grav = 9.8
// Velocity is in meters per second
// Angle is in radians
// Initial Height is in meters
// Returns: Horizontal distance travelled by object
function artillery(velocity, angle, initHeight) {
return Math.pow(velocity, 2) / (2 * grav) * (1 + Math.sqrt(1 + ((2*grav * initHeight) / (Math.pow(velocity, 2) * Math.pow(Math.sin(angle), 2))))) * Math.sin(2*angle)
}
/* Warning: This assumes that:
There is no air resistance
There is a uniform gravity field
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment