From 5c53e88521913ee1b7f4797e405d5eb70120a049 Mon Sep 17 00:00:00 2001 From: Mingye Wang Date: Tue, 10 Jan 2023 14:06:21 +0800 Subject: [PATCH 1/3] calcMortarSettings: Apply #80 (non-nato mils) Update the cMS script to match the #80 output. The GER/BR4/US6 mortars now give vel 119.89, quite close to the 119.93 calculated by @ansarto. Due to online editor laziness, I did not make separate mil functions, but just threw in a switch. --- calcMortarSettings.js | 48 +++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/calcMortarSettings.js b/calcMortarSettings.js index 1e958266..14b90277 100644 --- a/calcMortarSettings.js +++ b/calcMortarSettings.js @@ -145,11 +145,11 @@ const usa6cmTable = [ ]; const tables = [ - ["SQU", squadTable], - ["GER", gerTable], - ["BR3", br3inchTable], - ["BR4", br4inchTable], - ["US6", usa6cmTable], + ["SQU", squadTable, true], + ["GER", gerTable, false], + ["BR3", br3inchTable, false], + ["BR4", br4inchTable, false], + ["US6", usa6cmTable, false], ]; // gravity @@ -157,10 +157,13 @@ const g = 9.8; // deg to mil factor // "1mil = 1/6400 of a circle in NATO countries." -const milF = 360 / 6400; // deg to mil factor +const milFNato = 360 / 6400; +// standard miliradian +const milF = 360 / (2 * Math.PI * 1000); // conversions -function milToDeg(mil) { +function milToDeg(mil, nato) { + const mf = nato ? milFNato : milF; return mil * milF; } @@ -172,16 +175,17 @@ function radToDeg(rad) { return (rad * 180) / Math.PI; } -function degToMil(deg) { +function degToMil(deg, nato) { + const mf = nato ? milFNato : milF; return deg / milF; } -function radToMil(rad) { - return degToMil(radToDeg(rad)); +function radToMil(rad, nato) { + return degToMil(radToDeg(rad), nato); } -function milToRad(mil) { - return degToRad(milToDeg(mil)); +function milToRad(mil, nato) { + return degToRad(milToDeg(mil), nato); } // calculate time needed to hit target at distance x @@ -231,7 +235,7 @@ function findAngle(x, y, v) { const p1 = Math.sqrt(v ** 4 - g * (g * x ** 2 + 2 * y * v ** 2)); const a1 = Math.atan((v ** 2 + p1) / (g * x)); - // a2 is always below 800 mil -> can't be used in the game + // a2 is always below 800 mil -> can't be used in the game (direct fire) // const a2 = Math.atan((v ** 2 - p1) / (g * x)); return a1; @@ -250,8 +254,7 @@ const maxPrecision = 6; const startTime = Date.now(); tables.forEach((t) => { - const tName = t[0]; - const tTable = t[1]; + const [tName, tTable, tNato] = t; console.log(`${tName}: Gathering velocities...`); console.log(`${tName}: ===============================================`); @@ -259,9 +262,8 @@ tables.forEach((t) => { // get velocity per table row const velocities = []; tTable.forEach((entry) => { - const tDistance = entry[0]; - const tAngle = entry[1]; - const v = getVel(tDistance, milToRad(tAngle)); + const [tDistance, tAngle] = entry; + const v = getVel(tDistance, milToRad(tAngle, tNato)); velocities.push(v); console.log(`${tName}: ${pad(tDistance, 4)}m ${pad(tAngle, 4)}mil => ${v.toFixed(maxPrecision)}`); @@ -275,7 +277,7 @@ tables.forEach((t) => { console.log(`${tName}: ===============================================`); console.log(`${tName}: average velocity: ${avgVel.toFixed(maxPrecision)}`); - console.log(`${tName}: maximum distance: ${getDist(avgVel, milToRad(800)).toFixed(2)}`); + console.log(`${tName}: maximum distance: ${getDist(avgVel, milToRad(800, tNato)).toFixed(2)}`); console.log(`${tName}: ===============================================`); console.log(`${tName}: Minimizing deviation...`); console.log(`${tName}: ===============================================`); @@ -299,8 +301,7 @@ tables.forEach((t) => { const deviations = []; // eslint-disable-next-line no-loop-func tTable.forEach((entry) => { - const tDistance = entry[0]; - const tAngle = entry[1]; + const [tDistance, tAngle] = entry; const estimatedAngle = radToMil(findAngle(tDistance, 0, avgVel)); const d = tAngle - estimatedAngle; deviations.push(d); @@ -344,9 +345,8 @@ tables.forEach((t) => { // iterate through table yet again, printing table values, // calculated values based on optimized velocity, and deviation from table tTable.forEach((entry) => { - const tDistance = entry[0]; - const tAngle = entry[1]; - const v = getVel(tDistance, milToRad(tAngle)); + const [tDistance, tAngle] = entry; + const v = getVel(tDistance, milToRad(tAngle, tNato)); const estimatedAngle = radToMil(findAngle(tDistance, 0, avgVel)); const eAFormatted = pad(estimatedAngle.toFixed(1), 6); From 3d57d5655723628bdd48748fc44e5df8c9863551 Mon Sep 17 00:00:00 2001 From: Mingye Wang Date: Tue, 10 Jan 2023 14:15:31 +0800 Subject: [PATCH 2/3] Update calcMortarSettings.js --- calcMortarSettings.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/calcMortarSettings.js b/calcMortarSettings.js index 14b90277..6c87322c 100644 --- a/calcMortarSettings.js +++ b/calcMortarSettings.js @@ -335,7 +335,7 @@ tables.forEach((t) => { console.log(`${tName}: ===============================================`); console.log(`${tName}: FINAL VELOCITY : ${lAvgVel.toFixed(maxPrecision)}`); console.log(`${tName}: FINAL AVG DEVIATION: ${lAvgDev.toFixed(maxPrecision + 1)}`); - console.log(`${tName}: FINAL MAX RANGE : ${getDist(lAvgVel, milToRad(800)).toFixed(2)}`); + console.log(`${tName}: FINAL MAX RANGE : ${getDist(lAvgVel, milToRad(800, tNato)).toFixed(2)}`); console.log(`${tName}: ===============================================`); console.log(`${tName}: Generating overview...`); console.log(`${tName}: ===============================================`); From 21c6e2455d0bea2ec94c473fbca89b321668e952 Mon Sep 17 00:00:00 2001 From: Mingye Wang Date: Tue, 10 Jan 2023 19:33:21 +0800 Subject: [PATCH 3/3] use 45 degrees for maximum range to account for non-nato thing --- calcMortarSettings.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/calcMortarSettings.js b/calcMortarSettings.js index 6c87322c..a8c85d4a 100644 --- a/calcMortarSettings.js +++ b/calcMortarSettings.js @@ -277,7 +277,7 @@ tables.forEach((t) => { console.log(`${tName}: ===============================================`); console.log(`${tName}: average velocity: ${avgVel.toFixed(maxPrecision)}`); - console.log(`${tName}: maximum distance: ${getDist(avgVel, milToRad(800, tNato)).toFixed(2)}`); + console.log(`${tName}: maximum distance: ${getDist(avgVel, degToRad(45)).toFixed(2)}`); console.log(`${tName}: ===============================================`); console.log(`${tName}: Minimizing deviation...`); console.log(`${tName}: ===============================================`); @@ -335,7 +335,7 @@ tables.forEach((t) => { console.log(`${tName}: ===============================================`); console.log(`${tName}: FINAL VELOCITY : ${lAvgVel.toFixed(maxPrecision)}`); console.log(`${tName}: FINAL AVG DEVIATION: ${lAvgDev.toFixed(maxPrecision + 1)}`); - console.log(`${tName}: FINAL MAX RANGE : ${getDist(lAvgVel, milToRad(800, tNato)).toFixed(2)}`); + console.log(`${tName}: FINAL MAX RANGE : ${getDist(lAvgVel, degToRad(45)).toFixed(2)}`); console.log(`${tName}: ===============================================`); console.log(`${tName}: Generating overview...`); console.log(`${tName}: ===============================================`);