Skip to content

Instantly share code, notes, and snippets.

/muzzle_energy_calc1 Secret

Created Sep 14, 2014
Embed
What would you like to do?
/*
FILE ARCHIVED ON 22:30:31 Mar 20, 2006 AND RETRIEVED FROM THE
INTERNET ARCHIVE ON 22:24:59 Sep 14, 2014.
JAVASCRIPT APPENDED BY WAYBACK MACHINE, COPYRIGHT INTERNET ARCHIVE.
ALL OTHER CONTENT MAY ALSO BE PROTECTED BY COPYRIGHT (17 U.S.C.
SECTION 108(a)(3)).
*/
//copyright 2001 suessweb.com for airhog.com
function roundOff(val) //function to round off number to predetermined decimal places
{
val=val*1000.0; //prepare for rounding
val=Math.round(val); //rounds to integer value
val=val/1000.0; //divide by 1000 for three decimal places
return val;
}
function muzzle() //main function to determine and convert muzzle velocity, weight, and energy
{
vel = document.form0.v.value/1; //English units - velocity
wt = document.form0.w.value/1; //English units - weight
en = document.form0.e.value/1; //English units - energy
mvel = document.form0.mv.value/1; //metric units - velocity
mwt = document.form0.mw.value/1; //metric units - weight
men = document.form0.me.value/1; //metric units - energy
if (document.form0.m[0].checked) //English units selected
{
if (document.form0.v.value == "") //no value for v
{
if (document.form0.w.value == "") //no value for w
{
alert("Please enter two numbers in English units or choose Metric units.");
}
else if (document.form0.e.value == "") //no value for e
{
alert("Please enter two numbers in English units or choose Metric units.");
}
else //w, e have values (filtered from above)
{
tempa = en * 450240;
tempb = tempa / wt;
vel = Math.sqrt(tempb);
men = en / 0.7376;
mwt = wt / 15.432;
mvel = vel * 0.303;
document.form0.v.value = roundOff(vel);
document.form0.me.value = roundOff(men);
document.form0.mw.value = roundOff(mwt);
document.form0.mv.value = roundOff(mvel);
}
}
else if (document.form0.w.value == "") //no value for w
{
if (document.form0.e.value == "") //no value for e
{
alert("Please enter two numbers in English units\n\n or choose Metric units.");
}
else //v, e have values (filtered from above two decision statements)
{
tempa = en * 450240;
tempb = Math.pow(vel, 2);
wt = tempa / tempb;
men = en / 0.7376;
mwt = wt / 15.432;
mvel = vel * 0.303;
document.form0.w.value = roundOff(wt);
document.form0.me.value = roundOff(men);
document.form0.mw.value = roundOff(mwt);
document.form0.mv.value = roundOff(mvel);
}
}
else (document.form0.e.value == "") //no value for e
{
tempa = Math.pow(vel, 2);
tempb = tempa * wt;
en = tempb / 450240;
men = en / 0.7376;
mwt = wt / 15.432;
mvel = vel * 0.303;
document.form0.e.value = roundOff(en);
document.form0.me.value = roundOff(men);
document.form0.mw.value = roundOff(mwt);
document.form0.mv.value = roundOff(mvel);
}
} // end of English units calculations
if (document.form0.m[1].checked) //Metric units selected
{
if (document.form0.mv.value == "") // no value for v - metric
{
if (document.form0.mw.value == "") // no value for w - metric
{
alert("Please enter two numbers in Metric units \n\n or choose English units.");
}
else if (document.form0.me.value == "") // no value for e - metric
{
alert("Please enter two numbers in Metric units \n\n or choose English units.");
}
else
{
tempa = men * 2000;
tempb = tempa / mwt;
mvel = Math.sqrt(tempb);
vel = mvel * 3.3;
en = men / 1.3556;
wt = mwt * 15.432;
document.form0.v.value = roundOff(vel);
document.form0.e.value = roundOff(en);
document.form0.w.value = roundOff(wt);
document.form0.mv.value = roundOff(mvel);
}
}
else // v has value - metric (filtered from above)
if (document.form0.mw.value == "") // no value for w - metric
{
if (document.form0.me.value == "") // no value for e - metric
{
alert("Please enter two numbers in Metric units or choose English units.");
}
else // v, e have values - metric
{
tempa = men * 2000;
tempb = Math.pow(mvel, 2);
mwt = tempa / tempb;
wt = mwt * 15.432;
en = men / 1.3556;
vel = mvel * 3.3;
document.form0.w.value = roundOff(wt);
document.form0.v.value = roundOff(vel);
document.form0.e.value = roundOff(en);
document.form0.mw.value = roundOff(mwt);
}
}
else (document.form0.me.value == "") // v, w have values - metric (filtered from above two decision statements)
{
tempa = Math.pow(mvel, 2);
men = (mwt * tempa)/2000;
en = men / 1.3556;
wt = mwt * 15.432;
vel = mvel * 3.33;
document.form0.e.value = roundOff(en);
document.form0.v.value = roundOff(vel);
document.form0.w.value = roundOff(wt);
document.form0.me.value = roundOff(men);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.