反動計算機テスト

弾頭重量140gr 銃口初速2700fps 装薬重量45.5gr 装薬速度5200fps 銃の重量10 lbs = 8.557fps = 11.38ft-lbf

弾頭重量9.1g 銃口初速823m/s 装薬重量2.75g 装薬速度1585m/s 銃の重量4.54kg = 2.61m/s = 15.43 J

[recoil_calculator]

  • Create recoil energy calculator with JavaScript.
  • User can input number for bullet mass, muzzle velocity, powder mass, powder velocity, and gun mass.
  • User can input number directory into input form or input number into input form by using drop-down menu to select number.
  • Users can select metric or imperial units by using the drop-down menu.
  • when user press calculate button, this calculator output both result of recoil energy and gun velocity.
  • Use this formula to calculate when unit is metric;
  • “Recoil velocity = (bullet mass * muzzle velocity) + (powder mass * powder velocity)/ gun mass * 1000”
  • “Recoil energy = 0.5 * gun mass * recoil velocity * recoil velocity”
  • Use this formula to calculate when unit is imperial;
  • “Recoil velocity = (bullet mass * muzzle velocity) + (powder mass * powder velocity)/ gun mass * 7000”
  • “Recoil energy = gun mass * gun velocity * gun velocity / 2 * 32.1739”
  • Create JavaScript section only.
  • Code should be simple and as short as possible.
  • Do not create HTML and CSS sections.
  • Do not use unit conversion.

This form is going to use in this calculator;

jQuery(document).ready(function($) {
    function calculateRecoilEnergy() {
      const bulletMassValue = Number(document.getElementById('bulletMass').value);
      const muzzleVelocityValue = Number(document.getElementById('muzzleVelocity').value);
      const powderMassValue = Number(document.getElementById('powderMass').value);
      const powderVelocityValue = Number(document.getElementById('powderVelocity').value);
      const gunMassValue = Number(document.getElementById('gunMass').value);
  
      const unitSelector = document.getElementById('unitSelector');
      const unitSystem = unitSelector.value;
  
      let recoilVelocity, recoilEnergy;
  
      if (unitSystem === 'metric') {
        recoilVelocity = (bulletMassValue * muzzleVelocityValue + powderMassValue * powderVelocityValue) / (gunMassValue * 1000);
        recoilEnergy = 0.5 * gunMassValue * recoilVelocity * recoilVelocity;
      
        document.getElementById('recoilVelocityContainer').style.display = 'block';
        document.getElementById('recoilVelocityOutput').innerHTML = "反動速度<br>" + recoilVelocity.toFixed(2) + " m/s";
      
        document.getElementById('recoilEnergyContainer').style.display = 'block';
        document.getElementById('recoilEnergyOutput').innerHTML = "反動エネルギー<br>" + recoilEnergy.toFixed(2) + " J";
      } else if (unitSystem === 'imperial') {
        recoilVelocity = (bulletMassValue * muzzleVelocityValue + powderMassValue * powderVelocityValue) / (gunMassValue * 7000);
        recoilEnergy = gunMassValue * recoilVelocity * recoilVelocity / (2 * 32.1739);
      
        document.getElementById('recoilVelocityContainer').style.display = 'block';
        document.getElementById('recoilVelocityOutput').innerHTML = "反動速度<br>" + recoilVelocity.toFixed(2) + " fps";
      
        document.getElementById('recoilEnergyContainer').style.display = 'block';
        document.getElementById('recoilEnergyOutput').innerHTML = "反動エネルギー<br>" + recoilEnergy.toFixed(2) + " ft-lbf";
      }      

        // Show the output container
        $('#outputContainer').show();

        // Disable the unit selector after the button is clicked
        unitSelector.disabled = true;

        // Remove unit display from the output elements
        document.getElementById('recoilVelocityOutput').nextSibling.textContent = '';
        document.getElementById('recoilEnergyOutput').nextSibling.textContent = '';
    }

    function resetFields() {
        document.getElementById('bulletMass').value = '';
        document.getElementById('muzzleVelocity').value = '';
        document.getElementById('powderMass').value = '';
        document.getElementById('powderVelocity').value = '';
        document.getElementById('gunMass').value = '';
        document.getElementById('unitSelector').disabled = false;
        const outputElements = document.querySelectorAll("#recoilVelocityOutput, #recoilEnergyOutput");
        outputElements.forEach((element) => {
          element.innerHTML = "";
          const nextSibling = element.nextSibling;
          if (nextSibling && nextSibling.nodeName === "SPAN") {
            nextSibling.parentNode.removeChild(nextSibling);
          }
        });
      }

      $('#calculateBtn').on('click', function() {
        calculateRecoilEnergy();
      });
  
      $('#resetBtn').on('click', function() {
        resetFields();
      });
    });

    // Get references to the input fields and output elements
const bulletMassInput = document.getElementById("bulletMass");
const bulletMassUnit = document.createElement("span");
bulletMassUnit.innerHTML = "gr";
bulletMassInput.parentNode.insertBefore(bulletMassUnit, bulletMassInput.nextSibling);

const muzzleVelocityInput = document.getElementById("muzzleVelocity");
const muzzleVelocityUnit = document.createElement("span");
muzzleVelocityUnit.innerHTML = "fps";
muzzleVelocityInput.parentNode.insertBefore(muzzleVelocityUnit, muzzleVelocityInput.nextSibling);

const powderMassInput = document.getElementById("powderMass");
const powderMassUnit = document.createElement("span");
powderMassUnit.innerHTML = "gr";
powderMassInput.parentNode.insertBefore(powderMassUnit, powderMassInput.nextSibling);

const powderVelocityInput = document.getElementById("powderVelocity");
const powderVelocityUnit = document.createElement("span");
powderVelocityUnit.innerHTML = "fps";
powderVelocityInput.parentNode.insertBefore(powderVelocityUnit, powderVelocityInput.nextSibling);

const gunMassInput = document.getElementById("gunMass");
const gunMassUnit = document.createElement("span");
gunMassUnit.innerHTML = "lbs";
gunMassInput.parentNode.insertBefore(gunMassUnit, gunMassInput.nextSibling);

const recoilVelocityOutput = document.getElementById("recoilVelocityOutput");
const recoilVelocityUnit = document.createElement("span");
recoilVelocityUnit.innerHTML = "fps";
recoilVelocityOutput.parentNode.insertBefore(recoilVelocityUnit, recoilVelocityOutput.nextSibling);

const recoilEnergyOutput = document.getElementById("recoilEnergyOutput");
const recoilEnergyUnit = document.createElement("span");
recoilEnergyUnit.innerHTML = "ft-lbs";
recoilEnergyOutput.parentNode.insertBefore(recoilEnergyUnit, recoilEnergyOutput.nextSibling);

// Get references to the unit selector and set up an event listener
const unitSelector = document.getElementById("unitSelector");
unitSelector.addEventListener("change", updateUnits);

// Function to update the units based on the selected option
function updateUnits() {
  const unitSystem = unitSelector.value;
  
  if (unitSystem === "imperial") {
    bulletMassUnit.innerHTML = "gr";
    muzzleVelocityUnit.innerHTML = "fps";
    powderMassUnit.innerHTML = "gr";
    powderVelocityUnit.innerHTML = "fps";
    gunMassUnit.innerHTML = "lbs";
    recoilVelocityUnit.innerHTML = "fps";
    recoilEnergyUnit.innerHTML = "ft-lbs";
  } else if (unitSystem === "metric") {
    bulletMassUnit.innerHTML = "g";
    muzzleVelocityUnit.innerHTML = "m/s";
    powderMassUnit.innerHTML = "g";
    powderVelocityUnit.innerHTML = "m/s";
    gunMassUnit.innerHTML = "kg";
    recoilVelocityUnit.innerHTML = "m/s";
    recoilEnergyUnit.innerHTML = "J";
  }
}

// Call the updateUnits function to set the initial units based on the selected option
updateUnits();
  

メートル

Momentum long from:

反動速度 = (弾頭重量 x 銃口初速) + (装薬重量 x 装薬速度) / 銃の重量 x 1000.

リコイルエナジー = 0.5 x 銃の重量 x 反動速度の二乗

recoil velocity = (bullet mass * muzzle velocity) + (powder mass * powder velocity)/ gun mass * 1000

recoil energy = 0.5 * gun mass * recoil velocity * recoil velocity

Firearm: Mauser 98 chambered in 7 x 57 mm Mauser weighing 4.54 kilograms.
Projectile: spitzer type bullet weighing 9.1 grams with a muzzle velocity of 823 meters per second.
Powder charge: single base nitrocellulose weighing 2.75 grams with a powder charge velocity of 1585 meters per second.
2.61 m/s = (9.1 x 823) + (2.75 x 1585) / 4.54 x 1000.
Then, plug the now known Gun velocity of 2.61 meters per second into the translational kinetic energy formula:

15.43 J = 0.5 x 4.54 x 2.612.

Momentum short form:

リコイルエナジー = 0.5 x {[ (弾頭重量 x 銃口初速) + (装薬重量 x 装薬速度) / 1000]2} / 銃の重量

15.43 J = 0.5 x {[ (9.1 x 823) + (2.75 x 1585) / 1000]2} / 4.54.

ヤードポンド

Momentum long from:

Gun velocity = (bullet mass x bullet velocity) + (powder charge mass x powder charge velocity) / Gun mass x 7000.

Gun velocity = (bullet mass * muzzle velocity) + (powder mass * powder velocity)/ gun mass * 7000

Then, plug the now known Gun velocity into the translational kinetic energy formula:

Recoil energy = Gun mass x Gun velocity2 / 2 x dimensional constant.

Recoil energy = gun mass * gun velocity * gun velocity / 2 * 32.1739

Example:Firearm: Mauser 98 chambered in 7 x 57 mm Mauser weighing 10 pounds.Projectile: spitzer type bullet weighing 140 grains with a muzzle velocity of 2700 feet per second.Powder charge: single base nitrocellulose weighing 42.5 grains with a powder charge velocity of 5200 feet per second.

8.557 ft/s = (140 x 2700) + (42.5 x 5200) / 10 x 7000.

Then, plug the now known Gun velocity of 8.557 feet per second into the translational kinetic energy formula:

11.38 ft-lbf = 10 x 8.5572/ 2 x 32.163.


Momentum short form:

Recoil energy = {[ (bullet mass x bullet velocity) + (powder charge mass x powder charge velocity) / 7000]2} / Gun mass x 2 x dimensional constant.

11.38 ft-lbf = {[ (140 x 2700) + (42.5 x 5200) / 7000]2} / 10 x 2 x 32.163.

<?php
if (!defined('ABSPATH')) exit;

/**
 * Plugin Name: 反動計算機
 * Plugin URI: https://hb-plaza.com/
 * Description: 銃の反動を計算します。
 * Version: 1.0.0
 * Author: ポル
 * Author URI: https://hb-plaza.com/
 * License: GPL2
 */

// Add shortcode for the calculator
function recoil_energy_calculator_shortcode() {
  ob_start(); ?>
<form id="recoil-energy-calculator" style="max-width: 336px; margin: 0 auto; text-align: center;">
  <div style="margin-bottom: 10px;">
    <label for="bulletMass"><strong>弾頭重量</strong></label>
    <input type="number" id="bulletMass" name="bulletMass" step="0.01" required>
    <select id="bulletMassSelect" name="bulletMassSelect" style="text-align: center;">
      <option value="">選択してください</option>
      <option value="50">50</option>
      <option value="55">55</option>
      <option value="60">60</option>
    </select>
  </div>
  <div style="margin-bottom: 10px;">
    <label for="muzzleVelocity"><strong>銃口初速</strong></label>
    <input type="number" id="muzzleVelocity" name="muzzleVelocity" step="0.01" required>
    <select id="muzzleVelocitySelect" name="muzzleVelocitySelect" style="text-align: center;">
      <option value="">選択してください</option>
      <option value="2000">2000</option>
      <option value="2500">2500</option>
      <option value="3000">3000</option>
    </select>
  </div>
  <div style="margin-bottom: 10px;">
    <label for="powderMass"><strong>装薬重量</strong></label>
    <input type="number" id="powderMass" name="powderMass" step="0.01" required>
    <select id="powderMassSelect" name="powderMassSelect" style="text-align: center;">
      <option value="">選択してください</option>
      <option value="10">10</option>
      <option value="15">15</option>
      <option value="20">20</option>
    </select>
  </div>
  <div style="margin-bottom: 10px;">
    <label for="powderVelocity"><strong>装薬速度</strong></label>
    <input type="number" id="powderVelocity" name="powderVelocity" step="0.01" required>
    <select id="powderVelocitySelect" name="powderVelocitySelect" style="text-align: center;">
      <option value="">選択してください</option>
      <option value="2000">2000</option>
      <option value="2500">2500</option>
      <option value="3000">3000</option>
    </select>
  </div>
  <div style="margin-bottom: 10px;">
    <label for="gunMass"><strong>銃の重量</strong></label>
    <input type="number" id="gunMass" name="gunMass" step="0.01" required>
    <select id="gunMassSelect" name="gunMassSelect" style="text-align: center;">
      <option value="">選択してください</option>
      <option value="6">6</option>
      <option value="7">7</option>
      <option value="8">8</option>
    </select>
  </div>
  <div style="margin-bottom: 10px;">
    <label for="units"><strong>単位</strong></label>
    <select id="units" name="units" style="text-align: center;">
      <option value="imperial">ヤードポンド</option>
      <option value="metric">メートル</option>
    </select>
  </div>
  <button type="submit" style="width: 336px; background-color: #4865b2; color: #fff; font-size: 16px;"><strong>計算する</strong></button>
</form>
    <div id="recoil-energy-calculator-results"></div>
    <script>

// Wait for the page to load
window.addEventListener('load', function() {

// Get the form and its input elements
const form = document.getElementById('recoil-energy-calculator');
const bulletMass = form.querySelector('#bulletMass');
const bulletMassSelect = form.querySelector('#bulletMassSelect');
const muzzleVelocity = form.querySelector('#muzzleVelocity');
const muzzleVelocitySelect = form.querySelector('#muzzleVelocitySelect');
const powderMass = form.querySelector('#powderMass');
const powderMassSelect = form.querySelector('#powderMassSelect');
const powderVelocity = form.querySelector('#powderVelocity');
const powderVelocitySelect = form.querySelector('#powderVelocitySelect');
const gunMass = form.querySelector('#gunMass');
const gunMassSelect = form.querySelector('#gunMassSelect');

bulletMassSelect.addEventListener('change', function() {
  bulletMass.value = bulletMassSelect.value;
});

muzzleVelocitySelect.addEventListener('change', function() {
  muzzleVelocity.value = muzzleVelocitySelect.value;
});

powderMassSelect.addEventListener('change', function() {
  powderMass.value = powderMassSelect.value;
});

powderVelocitySelect.addEventListener('change', function() {
  powderVelocity.value = powderVelocitySelect.value;
});

gunMassSelect.addEventListener('change', function() {
  gunMass.value = gunMassSelect.value;
});

// Add event listener to input fields to reset the corresponding dropdown menu to default when the user types in a value
bulletMass.addEventListener('input', function() {
  bulletMassSelect.value = '';
});

muzzleVelocity.addEventListener('input', function() {
  muzzleVelocitySelect.value = '';
});

powderMass.addEventListener('input', function() {
  powderMassSelect.value = '';
});

powderVelocity.addEventListener('input', function() {
  powderVelocitySelect.value = '';
});

gunMass.addEventListener('input', function() {
  gunMassSelect.value = '';
});

// Get the hidden input elements for each select field
const bulletMassSelectHidden = form.querySelector('#bulletMassSelectHidden');
const muzzleVelocitySelectHidden = form.querySelector('#muzzleVelocitySelectHidden');
const powderMassSelectHidden = form.querySelector('#powderMassSelectHidden');
const powderVelocitySelectHidden = form.querySelector('#powderVelocitySelectHidden');
const gunMassSelectHidden = form.querySelector('#gunMassSelectHidden');

// Add event listeners to select elements
bulletMassSelect.addEventListener('change', function() {
  bulletMass.value = bulletMassSelect.value;
  bulletMassSelectHidden.value = bulletMassSelect.value;
});

muzzleVelocitySelect.addEventListener('change', function() {
  muzzleVelocity.value = muzzleVelocitySelect.value;
  muzzleVelocitySelectHidden.value = muzzleVelocitySelect.value;
});

powderMassSelect.addEventListener('change', function() {
  powderMass.value = powderMassSelect.value;
  powderMassSelectHidden.value = powderMassSelect.value;
});

powderVelocitySelect.addEventListener('change', function() {
  powderVelocity.value = powderVelocitySelect.value;
  powderVelocitySelectHidden.value = powderVelocitySelect.value;
});

gunMassSelect.addEventListener('change', function() {
  gunMass.value = gunMassSelect.value;
  gunMassSelectHidden.value = gunMassSelect.value;
});

  // Add event listener to form submission
  form.addEventListener('submit', function(event) {
    event.preventDefault(); // prevent form submission

        // Calculate recoil energy
        const mass = bulletMass + powderMass;
        const velocity = (muzzleVelocity + powderVelocity) / 2;
        const recoilEnergy = (mass * velocity * velocity) / (2 * gunMass);

    // Calculate recoil energy
const bulletMassValue = parseFloat(bulletMass.value || bulletMassSelect.value);
const muzzleVelocityValue = parseFloat(muzzleVelocity.value || muzzleVelocitySelect.value);
const powderMassValue = parseFloat(powderMass.value || powderMassSelect.value);
const powderVelocityValue = parseFloat(powderVelocity.value || powderVelocitySelect.value);
const gunMassValue = parseFloat(gunMass.value || gunMassSelect.value);
const unitsValue = form.querySelector('#units').value;

const mass = bulletMassValue + powderMassValue;
const velocity = (muzzleVelocityValue + powderVelocityValue) / 2;
const recoilEnergy = (mass * velocity * velocity) / (2 * gunMassValue);

// Calculate gun velocity
const gunVelocity = muzzleVelocityValue - (powderVelocityValue * (powderMassValue / bulletMassValue));

// Display results
const results = document.getElementById('recoil-energy-calculator-results');
results.innerHTML = `<p><strong>反動エネルギー:</strong> ${recoilEnergy.toFixed(2)} ${unitsValue === 'imperial' ? 'ft-lbs' : 'J'}</p>
                     <p><strong>銃の速度:</strong> ${gunVelocity.toFixed(2)} ${unitsValue === 'imperial' ? 'fps' : 'm/s'}</p>`;

  });

    </script>
<?php
    return ob_get_clean();
}
add_shortcode('recoil_energy_calculator', 'recoil_energy_calculator_shortcode');