Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,24 @@ stability factor (Sg)** — with a warning if the bullet is marginal (< 1.4) or
unstable (< 1.0) — and folds **spin drift** (Litz approximation, right/left twist
aware) into the wind/drift column.

### G1 / G7 ballistic coefficient

Enter the BC in whichever model your bullet is published in. Switching the
**G1 / G7** toggle converts the value in place — the same way the MOA/MRAD/cm
toggles work in the turret card — so you keep describing one bullet and the whole
app (trajectory table + target card) recalculates against the matching drag curve.
The line under the field always shows the equivalent in the other model.

The two BCs are related by equal retardation, `Cd_G1(M)/BC_G1 = Cd_G7(M)/BC_G7`,
so the conversion factor is just `Cd_G1(M) / Cd_G7(M)` read off the drag tables at
your bullet's own Mach number. That factor is clamped to Mach 1.5–3.0, where it
lands between 1.91 and 1.99 — matching the ~1.95 measured for modern boat-tails
(175 gr SMK: 0.475 G1 / 0.243 G7). Outside that band, and especially through the
transonic region, the ratio swings from 1.3 to 2.3 and is not meaningful.

> A converted BC is an approximation of a *measured* one. If your bullet has a
> published BC in the model you want to shoot, type that instead.

> Note: this is a helper/estimator. Verify against real dope before relying on it.

## Target card
Expand All @@ -62,10 +80,10 @@ reach is reported as *no solution* rather than silently estimated.

## Tests

`test.js` extracts the app's `<script>` from `index.html` and runs 38 assertions
`test.js` extracts the app's `<script>` from `index.html` and runs 46 assertions
against the pure functions (unit conversion, turret math, atmosphere, drag
interpolation, Miller stability, spin drift, trajectory-solver behaviour, and the
target-card row labels/solver):
interpolation, Miller stability, spin drift, trajectory-solver behaviour, G1↔G7
BC conversion, and the target-card row labels/solver):

```bash
node test.js
Expand Down
60 changes: 58 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ <h1>Full Trajectory Calculator</h1>
<div>
<label>Ballistic coefficient</label>
<input id="tBc" type="number" inputmode="decimal" value="0.243" min="0.001" step="0.001">
<div class="detail" id="tBcHint"></div>
</div>
<div>
<label>BC model</label>
Expand Down Expand Up @@ -522,7 +523,58 @@ <h1>Target Card</h1>
[4.00,0.2141],[4.50,0.2065],[5.00,0.2003]
];

function setDrag(m) { dragModel = m; syncToggles(); saveState(); refreshAll(); }
/* ---- G1 <-> G7 ballistic coefficient ----
A G1 and a G7 BC describe the same bullet against two different standard
projectiles. Equal retardation means Cd_G1(M)/BC_G1 = Cd_G7(M)/BC_G7, so
BC_G1 / BC_G7 = Cd_G1(M) / Cd_G7(M) — a velocity-dependent ratio we can read
straight off the drag tables. It is evaluated at the bullet's own Mach number,
clamped to the band where both tables behave: the transonic region swings the
ratio wildly (1.3 to 2.3) and would produce nonsense conversions. In the
clamped band it lands at 1.91-1.99, matching the ~1.95 measured for modern
boat-tails (175gr SMK: 0.475 G1 / 0.243 G7). */
const BC_MACH_MIN = 1.5, BC_MACH_MAX = 3.0;

function bcRatio(mach) {
const m = Math.min(BC_MACH_MAX, Math.max(BC_MACH_MIN, mach > 0 ? mach : 2));
return interpCd(DRAG_G1, m) / interpCd(DRAG_G7, m);
}

function convertBc(bc, from, to, mach) {
if (!(bc > 0) || from === to) return bc;
const r = bcRatio(mach);
return Math.round((to === 'G1' ? bc * r : bc / r) * 1000) / 1000;
}

// Muzzle Mach from the current velocity + temperature; NaN if not usable yet.
function muzzleMach() {
const mv = parseFloat($('tMv').value);
const t = parseFloat($('tTemp').value);
const sound = 331.3 * Math.sqrt(1 + (isFinite(t) && t > -273 ? t : 15) / 273.15);
return mv > 0 ? mv / sound : NaN;
}

function updateBcHint() {
const bc = parseFloat($('tBc').value);
const other = dragModel === 'G1' ? 'G7' : 'G1';
const v = convertBc(bc, dragModel, other, muzzleMach());
$('tBcHint').textContent = v > 0 && v !== bc
? `${bc} ${dragModel} ≈ ${v.toFixed(3)} ${other} for the same bullet`
: '';
}

// Switching model converts the BC in place, so the load stays the same bullet.
function setDrag(m) {
if (m !== dragModel) {
const el = $('tBc');
const v = convertBc(parseFloat(el.value), dragModel, m, muzzleMach());
if (v > 0) el.value = v;
}
dragModel = m;
syncToggles();
updateBcHint();
saveState();
refreshAll();
}
function setTwist(d) { twistDir = d; syncToggles(); saveState(); refreshAll(); }
function setTrajUnit(u) { trajUnit = u; syncToggles(); saveState(); refreshAll(); }

Expand Down Expand Up @@ -935,7 +987,10 @@ <h1>Target Card</h1>
saveState();
if (['clickCm', 'clicksPerMark', 'marksPerTurn'].includes(el.id)) refreshAll();
}));
document.querySelectorAll('#card2 input').forEach(el => el.addEventListener('input', saveState));
document.querySelectorAll('#card2 input').forEach(el => el.addEventListener('input', () => {
saveState();
if (['tBc', 'tMv', 'tTemp'].includes(el.id)) updateBcHint();
}));

// Target rows are rebuilt on add/remove, so listen on the container.
$('targetRows').addEventListener('input', e => {
Expand All @@ -955,6 +1010,7 @@ <h1>Target Card</h1>
syncToggles();
calc();
renderTargetRows();
updateBcHint();
</script>
</body>
</html>
40 changes: 40 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,46 @@ test('denser air = more drop', () => {
assert(thick.y < thin.y);
});

console.log('G1 <-> G7 BC conversion:');
const M_800 = 800 / (331.3 * Math.sqrt(1 + 15 / 273.15)); // ~2.35 Mach

test('ratio is Cd_G1/Cd_G7 at the reference Mach', () =>
approx(bcRatio(2), interpCd(DRAG_G1, 2) / interpCd(DRAG_G7, 2), 1e-12));
test('ratio sits in the measured 1.9-2.0 band across the supersonic range', () => {
for (const m of [1.5, 2, 2.35, 3]) {
const r = bcRatio(m);
assert(r > 1.9 && r < 2.0, 'Mach ' + m + ' gave ' + r.toFixed(3));
}
});
test('transonic and subsonic Machs are clamped, not trusted', () => {
approx(bcRatio(0.9), bcRatio(BC_MACH_MIN), 1e-12);
approx(bcRatio(9), bcRatio(BC_MACH_MAX), 1e-12);
approx(bcRatio(NaN), bcRatio(2), 1e-12); // no velocity yet -> Mach 2
});
test('175gr SMK 0.243 G7 converts near its published 0.475 G1', () => {
approx(convertBc(0.243, 'G7', 'G1', M_800), 0.475, 0.01);
});
test('conversion round-trips', () => {
const g1 = convertBc(0.243, 'G7', 'G1', M_800);
approx(convertBc(g1, 'G1', 'G7', M_800), 0.243, 0.0005);
});
test('G1 BC is always the larger number', () =>
assert(convertBc(0.3, 'G7', 'G1', M_800) > 0.3 && convertBc(0.3, 'G1', 'G7', M_800) < 0.3));
test('same model or bad input is left untouched', () => {
assert.strictEqual(convertBc(0.243, 'G7', 'G7', M_800), 0.243);
assert.strictEqual(convertBc(0, 'G7', 'G1', M_800), 0);
assert(isNaN(convertBc(NaN, 'G7', 'G1', M_800)));
});
test('converted BC keeps the trajectory the same bullet', () => {
const a1 = findZeroAngle({ ...P });
const g1bc = convertBc(0.243, 'G7', 'G1', M_800);
const Q = { ...P, bc: g1bc, table: DRAG_G1 };
const asG7 = simulate({ ...P }, a1, [600])[0];
const asG1 = simulate(Q, findZeroAngle(Q), [600])[0];
// Different drag curves, so not identical — but within a few cm at 600 m.
approx(asG1.y * 100, asG7.y * 100, 8, 'drop cm at 600 m');
});

console.log('target card:');
const TURRET = { clickCm: 0.25, perMark: 4, perTurn: 36 };
const CTX = { p: { ...P }, angle: findZeroAngle({ ...P }), sg: 1.7, massKg: 175 * GRAIN_TO_KG };
Expand Down
Loading