Pada program ini dibuat untuk menghitung kecepatan kendaraan pada setiap gear dengan input rpm mesin, gear ratio, final drive ratio dan diameter ban
Hitung Kecepatan Kendaraan per Gear
Hasil Kecepatan per Gear:
<!DOCTYPE html>
<html>
<head>
<title>Perhitungan Kecepatan Kendaraan</title>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
</head>
<body>
<h2>Hitung Kecepatan Kendaraan per Gear</h2>
<label for="rpm">RPM Mesin:</label>
<input type="number" id="rpm" value="3000"><br><br>
<label for="ratios">Gear Ratios (1-8, pisahkan dengan koma):</label><br>
<input type="text" id="ratios" value="3.5,2.8,2.2,1.8,1.4,1.1,0.9,0.8" size="50"><br><br>
<label for="finalDrive">Final Drive Ratio:</label>
<input type="number" id="finalDrive" value="4.1" step="0.1"><br><br>
<label for="tireDiameter">Diameter Ban (dalam cm):</label>
<input type="number" id="tireDiameter" value="65"><br><br>
<button onclick="hitungDanGambar()">Hitung dan Tampilkan Grafik</button>
<h3>Hasil Kecepatan per Gear:</h3>
<ul id="hasil"></ul>
<canvas id="grafikKecepatan" width="600" height="300"></canvas>
<script>
function hitungDanGambar() {
const rpm = parseFloat(document.getElementById("rpm").value);
const ratios = document.getElementById("ratios").value.split(',').map(r => parseFloat(r.trim()));
const finalDrive = parseFloat(document.getElementById("finalDrive").value);
const tireDiameterCm = parseFloat(document.getElementById("tireDiameter").value);
// Konversi diameter ke keliling ban dalam meter
const tireCircumference = Math.PI * (tireDiameterCm / 100); // meter
const hasilList = document.getElementById("hasil");
hasilList.innerHTML = "";
const gearLabels = [];
const speedData = [];
ratios.forEach((gearRatio, index) => {
const totalRatio = gearRatio * finalDrive;
const speed = (rpm * tireCircumference * 60) / (totalRatio * 1000); // km/jam
gearLabels.push(`Gear ${index + 1}`);
speedData.push(speed.toFixed(2));
const li = document.createElement("li");
li.textContent = `Gear ${index + 1}: ${speed.toFixed(2)} km/jam`;
hasilList.appendChild(li);
});
// Buat grafik
const ctx = document.getElementById("grafikKecepatan").getContext("2d");
if (window.myChart) {
window.myChart.destroy(); // Hapus grafik lama jika ada
}
window.myChart = new Chart(ctx, {
type: 'line',
data: {
labels: gearLabels,
datasets: [{
label: 'Kecepatan (km/jam)',
data: speedData,
borderColor: 'blue',
backgroundColor: 'lightblue',
fill: true,
tension: 0.3
}]
},
options: {
responsive: true,
plugins: {
title: {
display: true,
text: 'Grafik Kecepatan vs Gear'
}
},
scales: {
y: {
title: {
display: true,
text: 'Kecepatan (km/jam)'
}
},
x: {
title: {
display: true,
text: 'Gear'
}
}
}
}
});
}
</script>
</body>
</html>
Program dibawah ini merupakan lanjutan dari program diatas, program ini telah ditambahkan kemampuan unntuk mengihitung kecepatan yang didapat ketika diberi gaya hambatan udara dan menghitung waktu yang dibutuhkan untuk mencapai kecepatan maksimal pada setiap gear ratio.
Calculator penghitung kecepatan pada setiap gear dengan memperhitungkan gaya hambatan udara dan waktu tempuh pada setiap gear
Hasil perhitungan dan grafik:
<!DOCTYPE html>
<html>
<head>
<title>Calculator penghitung kecepatan pada setiap gear dengan memperhitungkan gaya hambatan udara dan waktu tempuh pada setiap gear</title>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
</head>
<body>
<h2>Calculator penghitung kecepatan pada setiap gear dengan memperhitungkan gaya hambatan udara dan waktu tempuh pada setiap gear</h2>
<label for="rpmMax">RPM :</label>
<input type="number" id="rpmMax" value="6000"><br><br>
<label for="ratios">Gear Ratios (1-8, pisahkan dengan koma):</label><br>
<input type="text" id="ratios" value="3.5,2.8,2.2,1.8,1.4,1.1,0.9,0.8" size="50"><br><br>
<label for="finalDrive">Final Drive Ratio:</label>
<input type="number" id="finalDrive" value="4.1"><br><br>
<label for="tireDiameter">Diameter Ban (cm):</label>
<input type="number" id="tireDiameter" value="65"><br><br>
<label for="mass">Massa Kendaraan (kg):</label>
<input type="number" id="mass" value="1200"><br><br>
<label for="airDensity">Air Density (kg/mยณ):</label>
<input type="number" id="airDensity" value="1.225"><br><br>
<label for="frontalArea">Frontal Area (mยฒ):</label>
<input type="number" id="frontalArea" value="2.2"><br><br>
<label for="cd">Drag Coefficient (Cd):</label>
<input type="number" id="cd" value="0.32"><br><br>
<label for="hp">Horsepower Mesin (HP):</label>
<input type="number" id="hp" value="150"><br><br>
<button onclick="hitungAkselerasi()">Hitung dan tampilkan grafik</button>
<h3>Hasil perhitungan dan grafik:</h3>
<ul id="hasil"></ul>
<canvas id="grafikKecepatan" width="600" height="300"></canvas>
<script>
function hitungAkselerasi() {
const rpmMax = parseFloat(document.getElementById("rpmMax").value);
const ratios = document.getElementById("ratios").value.split(',').map(r => parseFloat(r.trim()));
const finalDrive = parseFloat(document.getElementById("finalDrive").value);
const tireDiameterCm = parseFloat(document.getElementById("tireDiameter").value);
const mass = parseFloat(document.getElementById("mass").value);
const airDensity = parseFloat(document.getElementById("airDensity").value);
const frontalArea = parseFloat(document.getElementById("frontalArea").value);
const cd = parseFloat(document.getElementById("cd").value);
const hpAvailable = parseFloat(document.getElementById("hp").value);
const tireCircumference = Math.PI * (tireDiameterCm / 100); // meter
const hpWatt = hpAvailable * 745.7;
const hasilList = document.getElementById("hasil");
hasilList.innerHTML = "";
const gearLabels = [];
const speedMaxData = [];
const waktuTempuhData = [];
let currentSpeed = 0; // km/h
let totalTime = 0; // seconds
let previousRatio = null;
ratios.forEach((gearRatio, index) => {
const totalRatio = gearRatio * finalDrive;
const speedMax = (rpmMax * tireCircumference * 60) / (totalRatio * 1000); // km/h
const speedMaxMs = speedMax / 3.6;
const speedMinMs = currentSpeed / 3.6;
const avgSpeedMs = (speedMinMs + speedMaxMs) / 2;
const dragForce = 0.5 * airDensity * cd * frontalArea * avgSpeedMs ** 2;
const engineForce = hpWatt / avgSpeedMs;
const netForce = engineForce - dragForce;
const acceleration = netForce / mass;
const deltaV = speedMaxMs - speedMinMs;
const waktu = acceleration > 0 ? deltaV / acceleration : 0;
totalTime += waktu;
let rpmAfterShiftText = "";
if (previousRatio !== null) {
const previousTotalRatio = previousRatio * finalDrive;
const rpmAfterShift = rpmMax * (totalRatio / previousTotalRatio);
rpmAfterShiftText = `<br>RPM setelah shift: <b>${rpmAfterShift.toFixed(0)} RPM</b>`;
}
const li = document.createElement("li");
li.innerHTML = `<b>Gear ${index + 1}</b>:
Kecepatan ${currentSpeed.toFixed(2)} โ ${speedMax.toFixed(2)} km/jam,
Waktu: ${waktu.toFixed(2)} detik,
Total: ${totalTime.toFixed(2)} detik
${rpmAfterShiftText}`;
hasilList.appendChild(li);
// Update data for next loop
previousRatio = gearRatio;
currentSpeed = speedMax;
gearLabels.push(`Gear ${index + 1}`);
speedMaxData.push(speedMax.toFixed(2));
waktuTempuhData.push(totalTime.toFixed(2));
});
// Grafik
const ctx = document.getElementById("grafikKecepatan").getContext("2d");
if (window.myChart) window.myChart.destroy();
window.myChart = new Chart(ctx, {
type: 'line',
data: {
labels: gearLabels,
datasets: [{
label: 'Kecepatan Maksimum (km/jam)',
data: speedMaxData,
borderColor: 'blue',
backgroundColor: 'lightblue',
tension: 0.3
}, {
label: 'Waktu Kumulatif (detik)',
data: waktuTempuhData,
borderColor: 'orange',
backgroundColor: 'peachpuff',
tension: 0.3,
yAxisID: 'y1'
}]
},
options: {
responsive: true,
plugins: {
title: {
display: true,
text: 'Kecepatan & Waktu Akselerasi per Gear'
}
},
scales: {
y: {
type: 'linear',
position: 'left',
title: { display: true, text: 'Kecepatan (km/jam)' }
},
y1: {
type: 'linear',
position: 'right',
title: { display: true, text: 'Waktu (detik)' },
grid: { drawOnChartArea: false }
}
}
}
});
}
</script>
</body>
</html>