Last active
August 29, 2015 14:08
-
-
Save trevnorris/4441905856f0c8861c74 to your computer and use it in GitHub Desktop.
Crazy physics done in integer space, to prevent floating point calculations.
This file contains 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
// Distance is in 100nm segments. Will be rounding values in order to keep them | |
// in integer space. Hopefully no values exceed +/-2^53. | |
var D = 1e7; | |
var G = 9.80665 * D; | |
// Amount of time to calculate for. | |
var T = 10; | |
// Number of segments to divide time (60 fps). | |
var S = 60 * T; | |
// Initial velocity in m/sec | |
var V = 31; | |
// Calcuate new vector from pull of gravity over time t. | |
function delta_y(y0, t) { | |
return y0 - Math.round(G * t / D); | |
} | |
// Change in y over time, with initial y magnitude in 100 nm/sec. | |
var dy = [V * D]; | |
var dt = T / S * D; | |
for (var i = 0; i < S; i++) { | |
dy.push(delta_y(dy[i], dt)); | |
} | |
var dy_ms = []; | |
for (var i = 0; i < T; i++) { | |
dy_ms.push(dy[i * ((S / T) >>> 0)] / D); | |
} | |
dy_ms.push(dy[dy.length - 1] / D); | |
console.log(dy_ms); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment