Skip to content

nikolaygekht/ballistic.calculator.app.avalonia / .claude/skills/ballistic-calculator

ballistic-calculator

Verified

Use whenever writing, reviewing, or debugging .NET/C# code that uses the BallisticCalculator NuGet package (namespace BallisticCalculator) or its Gehtsoft.Measurements unit types — even when the user doesn't name the package explicitly but is clearly doing external/interior ballistics in .NET (bullet drop, velocity, energy, windage, spin drift, time of flight, zeroing a scope) for rifles, air rifles, bows, or artillery. Covers the full public API (Ammunition, Rifle, Atmosphere, Wind, ShotParameters, TrajectoryCalculator, TrajectoryPoint); standard, custom, .drg, and multi-BC drag tables; saving/loading data and building your own file format around it (BXml and System.Text.Json serialization); and building or rendering scope reticles (e.g. to SVG). Also use it for this library's Gehtsoft.Measurements Measurement<T> unit types (DistanceUnit, VelocityUnit, AngularUnit, WeightUnit, PressureUnit, …). Skip for: generic physics or projectile-motion exercises, a different ballistics library (e.g. GNU/JBM), game-engine or Unity projectile motion, plain unit conversions, and non-code ballistics questions (load-data or forensics advice). Self-contained: no access to the library source or binaries is required — prefer this over scanning the package to rediscover the API. Describes 1.1.13+, including the named ZeroRangeCantBeReachedException / TrajectoryCannotBeCalculatedException failures.

FileKindSize
SKILL.mdskill md21.8 KB
references/custom-drag.mdmarkdown3.8 KB
references/reticle.mdmarkdown6.5 KB
references/serialization.mdmarkdown7.8 KB

references/custom-drag.md

View on GitHub
# Custom drag curves

For anything beyond the standard `G1..RA4` curves — a measured/custom drag table, a radar `.drg`
file, or a multi-BC (BC-vs-Mach) profile. Standard curves come from `DragTable.Get(DragTableId.G7)`
and are applied automatically when the BC names a standard table; the techniques here all use table
id **`GC`** and require passing the `DragTable` instance to **both** `CalculateZeroParameters` and
`Calculate` (there is no `DragTable.Get(GC)` — it throws).

## A. A custom drag table in code
```csharp
class MyDrag : DragTable
{
    public override DragTableId TableId => DragTableId.GC;
    private static readonly DragTableDataPoint[] Points =   // (Mach, drag coefficient), ascending Mach
    {
        new DragTableDataPoint(0.00, 0.180), new DragTableDataPoint(0.90, 0.177),
        new DragTableDataPoint(1.00, 0.427), new DragTableDataPoint(1.20, 0.429),
        new DragTableDataPoint(2.00, 0.339), new DragTableDataPoint(3.00, 0.250),
    };
    public MyDrag() : base(Points) { }
}

var table = new MyDrag();
var ammo  = new Ammunition(weight, new BallisticCoefficient(0.5, DragTableId.GC), muzzleVelocity);
shot.Apply(calc.CalculateZeroParameters(ammo, atmosphere, rifle, rifle.Zero, dragTable: table));
var traj = calc.Calculate(ammo, rifle, atmosphere, shot, null, table);
```

## B. A radar `.drg` file
```csharp
DrgDragTable table = DrgDragTable.Open("308-168gr.drg");   // also Open(Stream)
// use `table` exactly like the custom table above (pass to CalculateZeroParameters and Calculate)
table.Save("copy.drg");                                    // also Save(Stream)
```

## C. Multi-BC → synthesized drag table (`DrgDragTableFactory`)
Turn a 2–3 point BC-vs-Mach profile (as published for many bullets) into a custom curve. It scales a
standard base curve by the BC at each Mach (piecewise-linear between knots, flat beyond the ends). Run
the result with a BC of **1.0** and table **`GC`**.

`Build` uses only its `baseTable` and `bcCurve` arguments to compute the curve; the
`AmmunitionLibraryEntry` is attached to the returned table as **metadata only** (name/source/caliber
etc.) and its numeric fields do *not* affect the drag curve. `baseTable` must be a standard curve
(passing `GC` throws), and every knot's BC must be positive.

`AmmunitionLibraryEntry` (properties): `Ammunition` (`Ammunition`), `Name`, `Source`, `Caliber`,
`AmmunitionType` (all `string`), `BarrelLength` (`Measurement<DistanceUnit>?`).
```csharp
var entry = new AmmunitionLibraryEntry
{
    Name = "220 gr .308",
    Ammunition = new Ammunition(
        weight: new Measurement<WeightUnit>(220, WeightUnit.Grain),
        ballisticCoefficient: new BallisticCoefficient(1.0, DragTableId.GC),
        muzzleVelocity: new Measurement<VelocityUnit>(2600, VelocityUnit.FeetPerSecond),
        bulletDiameter: new Measurement<DistanceUnit>(0.308, DistanceUnit.Inch)),
};

var curve = new[]                                       // Mach -> effective BC
{
    new BcAtMach(1.20, 0.307),
    new BcAtMach(1.65, 0.301),
    new BcAtMach(2.25, 0.318),
};

DrgDragTable table = DrgDragTableFactory.Build(entry, DragTableId.G7, curve);
// table.Save("220gr-308.drg");  // optional

var ammo = new Ammunition(
    weight: new Measurement<WeightUnit>(220, WeightUnit.Grain),
    ballisticCoefficient: new BallisticCoefficient(1.0, DragTableId.GC),
    muzzleVelocity: new Measurement<VelocityUnit>(2600, VelocityUnit.FeetPerSecond));
shot.Apply(calc.CalculateZeroParameters(ammo, atmosphere, rifle, rifle.Zero, dragTable: table));
var traj = calc.Calculate(ammo, rifle, atmosphere, shot, null, table);
```

## Signatures
`DragTable.Get(DragTableId)`, `DrgDragTable.Open(string|Stream)`,
`DrgDragTable.Save(string|Stream)`, `DrgDragTableFactory.Build(AmmunitionLibraryEntry, DragTableId, IEnumerable<BcAtMach>)`,
`new BcAtMach(double mach, double bc)`, `new DragTableDataPoint(double mach, double dragCoefficient)`.
receiving-code-reviewobra/superpowersUse when receiving code review feedback, before implementing suggestions, especially if feedback seems unclear or technically questionable - requires technical rigor and verification, not performative agreement or blind implementationStars: 323kUpdated Claude CodeCodexVerifiedInstall
requesting-code-reviewobra/superpowersUse when completing tasks, implementing major features, or before merging to verify work meets requirementsStars: 323kUpdated Claude CodeCodexVerifiedInstall
using-git-worktreesobra/superpowersUse when starting feature work that needs isolation from current workspace or before executing implementation plans - ensures an isolated workspace exists via native tools or git worktree fallbackStars: 323kUpdated Claude CodeCodexVerifiedInstall
verification-before-completionobra/superpowersUse when about to claim work is complete, fixed, or passing, before committing or creating PRs - requires running verification commands and confirming output before making any success claims; evidence before assertions alwaysStars: 323kUpdated Claude CodeCodexVerifiedInstall