calculateMillerStability function

double calculateMillerStability({
  1. required double twistInch,
  2. dynamic bulletLenInch,
  3. dynamic bulletDiamInch,
  4. dynamic bulletWghtGrains,
  5. dynamic muzzleVelocityFps,
  6. dynamic tempF,
  7. dynamic pressureInHg,
})

Implementation

double calculateMillerStability({
  required double twistInch,
  bulletLenInch,
  bulletDiamInch,
  bulletWghtGrains,
  muzzleVelocityFps,
  tempF,
  pressureInHg,
}) {
  twistInch = twistInch.abs();

  // Check for zero values (Python equivalent: if value)
  if (twistInch == 0.0 ||
      bulletLenInch == 0.0 ||
      bulletDiamInch == 0.0 ||
      bulletWghtGrains == 0.0 ||
      pressureInHg == 0.0) {
    return 0.0;
  }

  // Calculate twist rate and length ratios
  final twistRate = twistInch / bulletDiamInch;
  final length = bulletLenInch / bulletDiamInch;

  // Base Miller stability formula
  final sd =
      30.0 *
      bulletWghtGrains /
      (math.pow(twistRate, 2) *
          math.pow(bulletDiamInch, 3) *
          length *
          (1 + math.pow(length, 2)));

  // Velocity correction factor
  final fv = math.pow(muzzleVelocityFps / 2800.0, 1.0 / 3.0);

  // Atmospheric correction
  final ftp = ((tempF + 460.0) / (59.0 + 460.0)) * (29.92 / pressureInHg);

  return sd * fv * ftp;
}