Warning

 

Close
Confirm Action

Are you sure you wish to do this?

Cancel Confirm
AR15.COM
10/17/2013 7:42:05 AM EDT


I want to use some JavaScript
I found on the web.  The script in
question is found at http://arc.id.au/CannonBallistics.html.  I would like to use both the "Muzzle Velocity”
and "Ballistic Trajectory” code but have no idea how to accomplish this.







The code was written by
A. R. Collins , my first thought was to ask Mr. Collins for help but I have not
been able to find an address for him (in my web search the only person that
seems even remotely correct is the Dr. A. R. Collins who worked with Dr. Barns
Wallace on the Dam Buster project!).  I
searched for the web address using "whois” but that came up negative.







So, without being able
to contact the author for help, can anyone "complete” the code and/or explain
to me in bunny rabbit language how to make the code work?





As requested by Mr Collins, I will credit him as the author if and when I print any results.










I am pretty much programming
illiterate, I did look at a few JavaScript tutorials on the web but they just
made my head hurt.







Thanks in advance.







 
10/18/2013 7:56:23 AM EDT
[#1]
Are you trying to make a web page to use this on? If you go that route, you're 95% of the way there with the code that was given.









// Barrel bore for standard iron shot weights, windage of 25/24 is assumed
var bore = [];
bore[4] = 3.18;
bore[6] = 3.65;
bore[9] = 4.17;
bore[12] = 4.58;
bore[18] = 5.25;
bore[24] = 5.78;
bore[32] = 6.36;
bore[42] = 6.96;

// Muzzle Velocity as function of round shot mass and powder charge
function MuzzleVelocity(m, p) // mass of ball (lb), mass of charge (lb)
{
 var d = bore[m]/12;   // bore (ft) from table at ./Cannonballs.html
 var eta = 55;         // density of powder (lb/ft^3)
 var rho = 62.4;       // density of water
 var atm = 14.7*32.2*144;    // 14 psi x g atmospheric pressure (lbw/ft^2)
 var R = 1600;         // gunpowder gas pressure ratio to atm
 var L = d*18;         // (18 calibre) length barrel (ft)
 var c = p*4/(Math.PI*d*d*eta);  // length of charge in (ft)

 return Math.sqrt(2*R*atm/eta)*Math.sqrt(p/(m+p/3)*Math.log(L/c));
}

<input type="text" id="ball_mass" />
<input type="text" id="charge_mass" />
<button type="button" onclick="calcMuzzleVelocity();">Calculate</button>
<div id="result"></div>
User inputs values in those 2 text boxes and clicks calculate. You just need to provide the function to retrieve the input values, pass them to the MuzzleVelocity function then write the result out.





If you want, I can make an html page that would do all that. Just let me know.

 
10/18/2013 6:31:11 PM EDT
[#2]
Yes, I think I want to "activate" (?) that code on a web page; I thought that was the only way to use it?  I'm assuming it can be done so that I can simply open IE or Mozilla and access the code from my hard drive; I am not looking to post it on the web.



I also would like to add one more variable at the beginning of the code: bore [3] = 2.83.



Thanks

10/21/2013 6:38:12 AM EDT
[#3]
This should work, but it's not too pretty. I'm also assuming you'll probably just load the html file on your local machine rather than hosting it somewhere so I didn't include anything like jquery.




<html>
<head>
<script>
// Barrel bore for standard iron shot weights, windage of 25/24 is assumed
var bore = [];
bore[3] = 2.83;
bore[4] = 3.18;
bore[6] = 3.65;
bore[9] = 4.17;
bore[12] = 4.58;
bore[18] = 5.25;
bore[24] = 5.78;
bore[32] = 6.36;
bore[42] = 6.96;

// Muzzle Velocity as function of round shot mass and powder charge
function MuzzleVelocity(m, p) // mass of ball (lb), mass of charge (lb)
{
var d = bore[m]/12;   // bore (ft) from table at ./Cannonballs.html
var eta = 55;         // density of powder (lb/ft^3)
var rho = 62.4;       // density of water
var atm = 14.7*32.2*144;    // 14 psi x g atmospheric pressure (lbw/ft^2)
var R = 1600;         // gunpowder gas pressure ratio to atm
var L = d*18;         // (18 calibre) length barrel (ft)
var c = p*4/(Math.PI*d*d*eta);  // length of charge in (ft)

return Math.sqrt(2*R*atm/eta)*Math.sqrt(p/(m+p/3)*Math.log(L/c));
}

function CalculateVelocity()
{
var mv = document.getElementById("mv");
mv.value = '';
var b = document.getElementById("bMass");
var c = document.getElementById("cMass");
if (typeof bore[b.value] == 'undefined')
{
alert('invalid ball mass value.');
return;
}
if (isNaN(c.value) || c.value == '')
{
alert('invalid charge mass value.');
return;
}
mv.value = MuzzleVelocity(b.value,c.value);
}

</script>
</head>
<body>
<form>
<fieldset>
<legend>Ball Mass</legend>
<!--<input type="text" id="bMass"/>-->
<select id="bMass">
<option value="3">2.83</option>
<option value="4">3.18</option>
<option value="6">3.65</option>
<option value="9">4.17</option>
<option value="12">4.58</option>
<option value="18">5.25</option>
<option value="24">5.78</option>
<option value="32">6.36</option>
<option value="42">6.96</option>
</select>
</fieldset>
<fieldset>
<legend>Charge Mass</legend>
<input type="text" id="cMass"/>
</fieldset>
<fieldset>
<legend>Muzzle Velocity</legend>
<input type="text" readonly="readonly" id="mv"/>
</fieldset>
<button id="btnCalculate" onclick="CalculateVelocity()" type="button">Calculate</button>
</form>
</body>
</html>






10/21/2013 11:32:29 AM EDT
[#4]
Thanks, another stupid question: I am not interested in hosting this on a website but how do I "load the html file on my local machine" and how do I then make it work?



Sorry for these questions but I really am stumped by this stuff.
10/22/2013 7:04:36 AM EDT
[#5]
Open Notepad.exe (if on Windows)
Copy code and paste into Notepad.

Click File then Save As...

Change the "Save as type" dropdown to "All Files" instead of "Text Documents"

Put in a file name like "muzzlecalc.html" and select a location to save the file.

Once it's saved, you can just double click it and it will open in your internet browser.
11/3/2013 5:35:21 PM EDT
[#6]
Sessrumnir



First I have to say sorry for not getting back sooner; higher priorities took over.  I followed your directions and I now get the input screen but nothing happens when I input the numbers.



I'm not smart enough to work the math behind the formulas to see if it is correct or not; I will try to find someone who is smarter than I.



Thanks for the help; if I get it running I'll let you know.