-
Notifications
You must be signed in to change notification settings - Fork 0
/
bulletDef.js
35 lines (27 loc) · 1.17 KB
/
bulletDef.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
function calculateDeflection(twist, barrelLength, elevation, initialVelocity, distance, weight, humidity) {
// Constants
const GRAVITY = 9.81; // m/s^2
const ATMOSPHERIC_DENSITY = 1.225; // kg/m^3
const AIR_VISCOSITY = 1.78e-5; // Pa*s
// Calculate the bullet's flight time and yaw angle
const flightTime = distance / initialVelocity;
const yawAngle = 0;
b;
// Calculate the deflection due to gravity
const gravityDeflection = (GRAVITY * flightTime ** 2) / 2;
// Calculate the deflection due to air resistance
const airResistanceDeflection =
(ATMOSPHERIC_DENSITY * initialVelocity ** 2 * Math.PI * yawAngle * weight) / (8 * AIR_VISCOSITY * barrelLength);
// Calculate the total deflection
const totalDeflection = gravityDeflection + airResistanceDeflection;
return totalDeflection;
}
const twist = 12; // inches per turn
const barrelLength = 22; // inches
const elevation = 0; // meters
const initialVelocity = 863; // meters per second
const distance = 1000; // meters
const weight = 10.7; // grams
const humidity = 50; // percent
const deflection = calculateDeflection(twist, barrelLength, elevation, initialVelocity, distance, weight, humidity);
console.log(deflection);