-
Notifications
You must be signed in to change notification settings - Fork 402
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Ballistic Coefficient Calculator (#1948)
- Loading branch information
1 parent
cf29a87
commit 1e52018
Showing
5 changed files
with
226 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# <p align="center">Ballistic Coefficient Calculator</p> | ||
|
||
## Description :- | ||
|
||
Ballistic coefficient calculator is a tool used in ballistics to determine the ballistic coefficient of a projectile, such as a bullet. The ballistic coefficient is a measure of a projectile's ability to overcome air resistance during flight. It is an essential factor in understanding how a projectile will behave over long distances, including its trajectory, velocity, and the degree of wind drift. | ||
|
||
## Tech Stacks :- | ||
|
||
- HTML | ||
- CSS | ||
- JavaScript | ||
|
||
## Screenshots :- | ||
|
||
![image](https://github.com/user-attachments/assets/bbb67e72-4630-4d26-8fe4-3c1e376434af) | ||
|
||
![image](https://github.com/user-attachments/assets/9ec517fb-886e-496d-8186-3b667f0b4923) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<link rel="stylesheet" href="./style.css"> | ||
<title>Ballistic Coefficient Calculator</title> | ||
</head> | ||
|
||
<body> | ||
<div class="calculator"> | ||
<h1>Ballistic Coefficient Calculator</h1> | ||
<div class="form-group"> | ||
<label for="mass">Mass (grams):</label> | ||
<input type="number" id="mass" placeholder="Enter mass" onkeydown="moveToNextField(event, 'diameter')"> | ||
<div class="info">Mass affects the projectile's inertia. Higher mass typically increases the ballistic coefficient.</div> | ||
</div> | ||
<div class="form-group"> | ||
<label for="diameter">Diameter (mm):</label> | ||
<input type="number" id="diameter" placeholder="Enter diameter" onkeydown="moveToNextField(event, 'drag-coefficient')"> | ||
<div class="info">Diameter is used to calculate the cross-sectional area, influencing air resistance.</div> | ||
</div> | ||
<div class="form-group"> | ||
<label for="drag-coefficient">Drag Coefficient (Cd):</label> | ||
<input type="number" id="drag-coefficient" placeholder="Enter drag coefficient" onkeydown="moveToNextField(event, 'velocity')"> | ||
<div class="info">The drag coefficient quantifies how streamlined the projectile is. Lower Cd reduces air resistance.</div> | ||
</div> | ||
<div class="form-group"> | ||
<label for="velocity">Initial Velocity (m/s):</label> | ||
<input type="number" id="velocity" placeholder="Enter initial velocity" onkeydown="moveToNextField(event, 'wind-speed')"> | ||
<div class="info">Initial velocity determines the speed of the projectile at launch, affecting its range and trajectory.</div> | ||
</div> | ||
<div class="form-group"> | ||
<label for="wind-speed">Wind Speed (m/s):</label> | ||
<input type="number" id="wind-speed" placeholder="Enter wind speed" onkeydown="moveToNextField(event, 'angle')"> | ||
<div class="info">Wind speed influences the drift of the projectile during flight.</div> | ||
</div> | ||
<div class="form-group"> | ||
<label for="angle">Launch Angle (degrees):</label> | ||
<input type="number" id="angle" placeholder="Enter launch angle"> | ||
<div class="info">The launch angle determines the trajectory and maximum range of the projectile.</div> | ||
</div> | ||
<button class="btn" onclick="calculateBallisticDetails()">Calculate</button> | ||
<div id="result" class="result" style="display: none;"></div> | ||
</div> | ||
|
||
<script src="./script.js"></script> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
function calculateBallisticDetails() { | ||
const mass = parseFloat(document.getElementById('mass').value); | ||
const diameter = parseFloat(document.getElementById('diameter').value); | ||
const dragCoefficient = parseFloat(document.getElementById('drag-coefficient').value); | ||
const velocity = parseFloat(document.getElementById('velocity').value); | ||
const windSpeed = parseFloat(document.getElementById('wind-speed').value); | ||
const angle = parseFloat(document.getElementById('angle').value); | ||
|
||
if (isNaN(mass) || isNaN(diameter) || isNaN(dragCoefficient) || isNaN(velocity) || isNaN(windSpeed) || isNaN(angle)) { | ||
alert('Please enter valid numeric values.'); | ||
return; | ||
} | ||
|
||
// Convert mass to kilograms and diameter to meters | ||
const massKg = mass / 1000; | ||
const diameterM = diameter / 1000; | ||
|
||
// Calculate the cross-sectional area | ||
const area = Math.PI * Math.pow(diameterM / 2, 2); | ||
|
||
// Calculate the ballistic coefficient | ||
const ballisticCoefficient = massKg / (dragCoefficient * area); | ||
|
||
// Calculate trajectory details | ||
const gravity = 9.81; // Acceleration due to gravity (m/s^2) | ||
const angleRad = (Math.PI / 180) * angle; // Convert angle to radians | ||
const timeOfFlight = (2 * velocity * Math.sin(angleRad)) / gravity; | ||
const maxHeight = Math.pow(velocity * Math.sin(angleRad), 2) / (2 * gravity); | ||
const range = (Math.pow(velocity, 2) * Math.sin(2 * angleRad)) / gravity; | ||
const windDrift = windSpeed * timeOfFlight; | ||
|
||
// Display the result | ||
const resultElement = document.getElementById('result'); | ||
resultElement.style.display = 'block'; | ||
resultElement.innerHTML = ` | ||
<p>Ballistic Coefficient: ${ballisticCoefficient.toFixed(4)} kg/m²</p> | ||
<p>Time of Flight: ${timeOfFlight.toFixed(2)} s</p> | ||
<p>Maximum Height: ${maxHeight.toFixed(2)} m</p> | ||
<p>Range: ${range.toFixed(2)} m</p> | ||
<p>Wind Drift: ${windDrift.toFixed(2)} m</p> | ||
`; | ||
} | ||
|
||
function moveToNextField(event, nextFieldId) { | ||
if (event.key === 'Enter') { | ||
event.preventDefault(); // Prevent form submission on Enter | ||
const nextField = document.getElementById(nextFieldId); | ||
if (nextField) { | ||
nextField.focus(); // Focus the next input field | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
body { | ||
font-family: Arial, sans-serif; | ||
margin: 0; | ||
padding: 0; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
height: 100%; | ||
min-height: 100vh; | ||
color: white; | ||
background: linear-gradient(135deg, #0f2027, #203a43, #2c5364); | ||
} | ||
|
||
.calculator { | ||
background: #9198a1; | ||
padding: 20px; | ||
border-radius: 10px; | ||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); | ||
max-width: 400px; | ||
width: 100%; | ||
} | ||
|
||
.calculator h1 { | ||
text-align: center; | ||
margin-bottom: 20px; | ||
font-size: 1.5rem; | ||
} | ||
|
||
.form-group { | ||
margin-bottom: 15px; | ||
position: relative; | ||
} | ||
|
||
.form-group label { | ||
display: block; | ||
margin-bottom: 5px; | ||
font-weight: bold; | ||
} | ||
|
||
.form-group input { | ||
width: 100%; | ||
padding: 8px; | ||
box-sizing: border-box; | ||
border: 1px solid #ccc; | ||
border-radius: 5px; | ||
font-size: 1rem; | ||
} | ||
|
||
.form-group input:focus { | ||
border-color: #007BFF; | ||
outline: none; | ||
} | ||
|
||
.info { | ||
display: none; | ||
font-size: 0.9rem; | ||
color: #555; | ||
margin-top: 5px; | ||
position: absolute; | ||
/* top: -50%; */ | ||
left: 50%; | ||
right: 0; | ||
background: #f9f9f9; | ||
padding: 10px; | ||
border: 1px solid #ccc; | ||
border-radius: 5px; | ||
z-index: 10; | ||
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); | ||
} | ||
|
||
.form-group input:focus+.info { | ||
display: block; | ||
} | ||
|
||
.btn { | ||
width: 100%; | ||
padding: 10px; | ||
background-color: #007BFF; | ||
color: #fff; | ||
border: none; | ||
border-radius: 5px; | ||
font-size: 1rem; | ||
cursor: pointer; | ||
margin-top: 10px; | ||
} | ||
|
||
.btn:hover { | ||
background-color: #0056b3; | ||
} | ||
|
||
.result { | ||
margin-top: 20px; | ||
padding: 10px; | ||
background-color: #e9ecef; | ||
color: black; | ||
border-radius: 5px; | ||
text-align: center; | ||
font-size: 1.2rem; | ||
font-weight: bold; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters