Skip to content

Instantly share code, notes, and snippets.

@iahuang
Last active November 30, 2020 03:43
Show Gist options
  • Save iahuang/573be98342c4cd97f41e64b186867a9c to your computer and use it in GitHub Desktop.
Save iahuang/573be98342c4cd97f41e64b186867a9c to your computer and use it in GitHub Desktop.
// very small utility library for doing physics calculations in a js console
// designed mostly for my physics homework
(function () {
window.Cos = function (x) { // degree cosine
return Math.cos(x * 0.01745329251);
};
window.Sin = function (x) { // degree sine
return Math.sin(x * 0.01745329251);
};
window.Tan = function (x) { // degree tangent
return Math.tan(x * 0.01745329251);
};
window.g = 10; // positive gravity on earth
window.rnd = function (x) {
return Number.parseFloat(x).toPrecision(3);
};
window.setMu = function (ms, mk) {
window.Ms = ms;
window.Mk = mk;
};
window.gsint = function() { // shorthand for g*sin(theta)
return Sin(theta)*g
};
window.gcost = function() { // shorthand for g*cos(theta)
return Cos(theta)*g
};
window.theta = 0;
})();
window.Cos=function(n){return Math.cos(.01745329251*n)},window.Sin=function(n){return Math.sin(.01745329251*n)},window.Tan=function(n){return Math.tan(.01745329251*n)},window.g=10,window.rnd=function(n){return Number.parseFloat(n).toPrecision(3)},window.setMu=function(n,t){window.Ms=n,window.Mk=t},window.gsint=function(){return Sin(theta)*g},window.gcost=function(){return Cos(theta)*g},window.theta=0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment