Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Torque Calculator #879

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 91 additions & 0 deletions Calculators/Torque-Calculator/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Torque Calculator</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="container">
<h1>Torque Calculator</h1>
<div class="method-selector">
<label for="method">Select Calculation Method:</label>
<select id="method" onchange="showMethod()">
<option value="force-radius">Force and Radius</option>
<option value="power-angular-velocity">Power and Angular Velocity</option>
<option value="moment-angular-acceleration">Moment of Inertia and Angular Acceleration</option>
</select>
</div>

<div id="force-radius" class="method">
<div class="input-group">
<label for="force">Force:</label>
<input type="number" id="force" placeholder="Enter force">
<select id="force-unit">
<option value="N">Newton (N)</option>
<option value="lbf">Pound-force (lbf)</option>
<option value="kN">Kilonewton (kN)</option>
<option value="kgf">Kilogram-force (kgf)</option>
</select>
</div>
<div class="input-group">
<label for="radius">Radius:</label>
<input type="number" id="radius" placeholder="Enter radius">
<select id="radius-unit">
<option value="m">Meters (m)</option>
<option value="cm">Centimeters (cm)</option>
<option value="mm">Millimeters (mm)</option>
<option value="ft">Feet (ft)</option>
<option value="in">Inches (in)</option>
</select>
</div>
</div>

<div id="power-angular-velocity" class="method" style="display:none;">
<div class="input-group">
<label for="power">Power:</label>
<input type="number" id="power" placeholder="Enter power">
<select id="power-unit">
<option value="W">Watt (W)</option>
<option value="kW">Kilowatt (kW)</option>
<option value="hp">Horsepower (hp)</option>
</select>
</div>
<div class="input-group">
<label for="angular-velocity">Angular Velocity:</label>
<input type="number" id="angular-velocity" placeholder="Enter angular velocity">
<select id="angular-velocity-unit">
<option value="rad/s">Radians per second (rad/s)</option>
<option value="rpm">Revolutions per minute (rpm)</option>
</select>
</div>
</div>

<div id="moment-angular-acceleration" class="method" style="display:none;">
<div class="input-group">
<label for="moment">Moment of Inertia:</label>
<input type="number" id="moment" placeholder="Enter moment of inertia">
<select id="moment-unit">
<option value="kgm2">Kilogram-meter² (kg·m²)</option>
</select>
</div>
<div class="input-group">
<label for="angular-acceleration">Angular Acceleration:</label>
<input type="number" id="angular-acceleration" placeholder="Enter angular acceleration">
<select id="angular-acceleration-unit">
<option value="rad/s2">Radians per second² (rad/s²)</option>
</select>
</div>
</div>

<button onclick="calculateTorque()">Calculate Torque</button>
<div class="result">
<h2>Torque: <span id="torque-result">0</span> Nm</h2>
</div>
</div>
<script src="script.js"></script>
</body>
</html>


73 changes: 73 additions & 0 deletions Calculators/Torque-Calculator/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
function showMethod() {
const method = document.getElementById('method').value;
const methods = document.querySelectorAll('.method');
methods.forEach(m => m.style.display = 'none');
document.getElementById(method).style.display = 'block';
}

function calculateTorque() {
const method = document.getElementById('method').value;

let torque = 0;

if (method === 'force-radius') {
const force = parseFloat(document.getElementById('force').value);
const forceUnit = document.getElementById('force-unit').value;
const radius = parseFloat(document.getElementById('radius').value);
const radiusUnit = document.getElementById('radius-unit').value;

const forceConversion = {
'N': 1,
'lbf': 4.44822,
'kN': 1000,
'kgf': 9.80665
};

const radiusConversion = {
'm': 1,
'cm': 0.01,
'mm': 0.001,
'ft': 0.3048,
'in': 0.0254
};

const forceInN = force * forceConversion[forceUnit];
const radiusInM = radius * radiusConversion[radiusUnit];

torque = forceInN * radiusInM;
}

if (method === 'power-angular-velocity') {
const power = parseFloat(document.getElementById('power').value);
const powerUnit = document.getElementById('power-unit').value;
const angularVelocity = parseFloat(document.getElementById('angular-velocity').value);
const angularVelocityUnit = document.getElementById('angular-velocity-unit').value;

const powerConversion = {
'W': 1,
'kW': 1000,
'hp': 745.7
};

const angularVelocityConversion = {
'rad/s': 1,
'rpm': 2 * Math.PI / 60
};

const powerInW = power * powerConversion[powerUnit];
const angularVelocityInRadS = angularVelocity * angularVelocityConversion[angularVelocityUnit];

torque = powerInW / angularVelocityInRadS;
}

if (method === 'moment-angular-acceleration') {
const moment = parseFloat(document.getElementById('moment').value);
const angularAcceleration = parseFloat(document.getElementById('angular-acceleration').value);

torque = moment * angularAcceleration;
}

document.getElementById('torque-result').textContent = torque.toFixed(2);
}


78 changes: 78 additions & 0 deletions Calculators/Torque-Calculator/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
body {
font-family: 'Arial', sans-serif;
background-color: #e0f7fa;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}

.container {
background: #ffffff;
padding: 30px;
border-radius: 10px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
text-align: center;
max-width: 400px;
width: 100%;
}

h1 {
color: #00796b;
margin-bottom: 20px;
}

.method-selector {
margin-bottom: 20px;
}

.input-group {
margin-bottom: 20px;
text-align: left;
}

label {
display: block;
margin-bottom: 5px;
color: #00796b;
font-weight: bold;
}

input, select {
padding: 10px;
width: calc(100% - 22px);
margin-bottom: 10px;
border: 1px solid #b2dfdb;
border-radius: 4px;
font-size: 16px;
}

button {
padding: 10px 20px;
background-color: #00796b;
color: #fff;
border: none;
border-radius: 4px;
font-size: 16px;
cursor: pointer;
}

button:hover {
background-color: #004d40;
}

.result {
margin-top: 20px;
}

#torque-result {
font-size: 24px;
color: #00796b;
}

.method {
display: none;
}


16 changes: 15 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ <h3>solves cubic equations, providing real or complex solutions</h3>
<h2>Currency Calculator</h2>
<h3>Converts the value of one Currency unit into another Currency unit.</h3>
<div class="card-footer">
<a href="./Calculators/Currency-Calculator/Currency-Calculator.html" target="_blank">
<a href="./Calculators/Currency-Calculator/index.html" target="_blank">
<button>Try Now</button>
</a>
<a href="https://github.com/Rakesh9100/CalcDiverse/tree/main/Calculators/Currency-Calculator" title="Source Code" target="_blank">
Expand Down Expand Up @@ -1798,6 +1798,20 @@ <h3>Instantly find the time difference anywhere in the world.</h3>
</div>
</div>
</div>
<div class="box">
<div class="content">
<h2>Torque calculator</h2>
<h3>Calculate the Torque produced through different processes</h3>
<div class="card-footer">
<a href="./Calculators/Torque-Calculator/index.html" target="_blank">
<button>Try Now</button>
</a>
<a href="https://github.com/Rakesh9100/CalcDiverse/tree/main/Calculators/Torque-Calculator" title="Source Code" target="_blank">
<img src="./assets/images/github.png" alt="Source Code"></img>
</a>
</div>
</div>
</div>
<div class="box">
<div class="content">
<h2>Triangle Calculator</h2>
Expand Down