Crates.io | ballistics_rs |
lib.rs | ballistics_rs |
version | 0.1.5 |
source | src |
created_at | 2024-09-07 14:51:18.417437 |
updated_at | 2024-09-21 04:34:29.866709 |
description | A Rust library for ballistics calculations |
homepage | https://github.com/CM-IV/ballistics-rs |
repository | https://github.com/CM-IV/ballistics-rs |
max_upload_size | |
id | 1367278 |
size | 25,315 |
ballistics_rs
is a Rust crate designed for external ballistics calculations. It provides utilities and equations to help developers create ballistics solver programs. This crate includes functions to calculate the speed of sound, kinetic energy, gyroscopic stability, and ballistic coefficient of projectiles.
To use ballistics_rs
in your project, add the following to your Cargo.toml
:
[dependencies]
ballistics_rs = "0.1.4"
Calculate the speed of sound in air given the temperature:
use ballistics_rs::{SpeedOfSound, Temperature};
let speed = SpeedOfSound::calculate()
.temperature(Temperature(68.0))
.solve();
println!("Speed of sound: {} ft/s", speed.0);
Calculate the kinetic energy of a bullet:
use ballistics_rs::{KineticEnergy, BulletWeight, Velocity};
let energy = KineticEnergy::calculate()
.bullet_weight(BulletWeight(150.0))
.velocity(Velocity(3000.0))
.solve();
println!("Kinetic energy: {} ft-lbs", energy.0);
Determine the movement of your point of aim for each click of an aperture:
use ballistics_rs::{ApertureSightCalibration, SightCalibration};
let calibration = ApertureSightCalibration::calculate()
.sight_movement_twenty_clicks(SightCalibration(0.1))
.sight_radius(SightCalibration(28.0))
.solve();
println!("MOA per click: {}", calibration.0);
Calculate the form factor of a bullet:
use ballistics_rs::{FormFactor, DragCoefficient};
let form_factor = FormFactor::calculate()
.drag_coefficient(DragCoefficient(0.223))
.standard_bullet_drag_coefficient(DragCoefficient(0.2))
.solve();
println!("Form factor: {}", form_factor.0);
Project the velocity of a second bullet based on the weight and velocity of a first bullet:
use ballistics_rs::{VelocityProjection, BulletWeight, Velocity};
let projected_velocity = VelocityProjection::calculate()
.bullet_weight_1(BulletWeight(150.0))
.bullet_weight_2(BulletWeight(180.0))
.bullet_velocity_1(Velocity(3000.0))
.solve();
println!("Projected velocity of second bullet: {} ft/s", projected_velocity.0);
Calculate the lag time of a bullet:
use ballistics_rs::{LagTime, TimeOfFlight, Distance, Velocity};
let lag_time = LagTime::calculate()
.actual_time_of_flight(TimeOfFlight(1.2))
.distance(Distance(1000.0))
.muzzle_velocity(Velocity(3000.0))
.solve();
println!("Lag time: {} seconds", lag_time.0);
Calculate the wind deflection of a bullet:
use ballistics_rs::{WindDeflection, LagTime, WindSpeed};
let wind_deflection = WindDeflection::calculate()
.lag_time(LagTime(0.1))
.crosswind_speed(WindSpeed(10.0))
.solve();
println!("Wind deflection: {} inches", wind_deflection.0);
Calculate the aerodynamic jump of a bullet:
use ballistics_rs::{AerodynamicJump, GyroscopicStability, BulletLength};
let jump = AerodynamicJump::calculate()
.gyro_stability(GyroscopicStability(1.5))
.bullet_length(BulletLength(4.0))
.solve();
println!("Aerodynamic jump: {} MOA", jump.0);
Calculate the gyroscopic stability factor of a bullet:
use ballistics_rs::{GyroscopicStability, BulletWeight, RiflingTwist, BulletDiameter, BulletLength, Velocity, Temperature, Pressure};
let stability = GyroscopicStability::calculate()
.bullet_weight(BulletWeight(150.0))
.rifling_twist(RiflingTwist(10.0))
.bullet_diameter(BulletDiameter(0.308))
.bullet_length(BulletLength(4.0))
.solve();
let velocity_corrected = GyroscopicStability::velocity_correction()
.muzzle_velocity(Velocity(3000.0))
.gyro_stability(stability)
.solve();
let atmospheric_corrected = GyroscopicStability::atmospheric_correction()
.air_temp(Temperature(68.0))
.air_pressure(Pressure(29.92))
.gyro_stability(velocity_corrected)
.solve();
println!("Gyroscopic stability factor: {}", atmospheric_corrected.0);
Calculate the spin drift of a bullet in the direction of rifling twist:
use ballistics_rs::{GyroscopicStability, TimeOfFlight, SpinDrift};
let spin_drift = SpinDrift::calculate()
.gyro_stability(GyroscopicStability(1.5))
.actual_time_of_flight(TimeOfFlight(1.2))
.solve();
println!("Spin drift: {}", spin_drift.0);
Calculate the ballistic coefficient of a bullet:
use ballistics_rs::{BallisticCoefficient, BulletWeight, BulletDiameter, FormFactor};
let bc = BallisticCoefficient::calculate()
.bullet_weight(BulletWeight(150.0))
.bullet_diameter(BulletDiameter(0.308))
.form_factor(FormFactor(1.0))
.solve();
println!("Ballistic coefficient: {}", bc.0);
The crate also provides several constants for use in calculations:
use ballistics_rs::constants::{STANDARD_GRAVITY, SPEED_OF_SOUND_SEA_LEVEL, AIR_DENSITY_SEA_LEVEL, STANDARD_PRESSURE, STANDARD_TEMPERATURE};
println!("Speed of Sound at Sea Level: {} ft/s", SPEED_OF_SOUND_SEA_LEVEL.0);
println!("Air Density at Sea Level: {} lb/ft³", AIR_DENSITY_SEA_LEVEL.0);
println!("Standard Gravity: {} ft/s²", STANDARD_GRAVITY.0);
println!("Standard Pressure: {} inHg", STANDARD_PRESSURE.0);
println!("Standard Temperature: {} F", STANDARD_TEMPERATURE.0);