Created
September 12, 2024 17:12
-
-
Save eugenserbanescu/d4a75246c6be914170cb3c44fdbad270 to your computer and use it in GitHub Desktop.
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
const mmInOneInch = 25.4; | |
const mockRpm = 3000; | |
const tyreWidthInMm = 225; | |
const tyreHeightInPercentage = 45; | |
const tyreRimHeightInInch = 17; | |
const finalRatio = 3.38; | |
const someRevs = [2000, 2500, 3000, 4500, 5000, 5500]; | |
const mockGearboxRatios = { | |
1: 4.23, | |
2: 2.52, | |
3: 1.66, | |
4: 1.22, | |
5: 1 | |
}; | |
function getTyreHeightInMm(widthInMm, aspectRatio) { | |
const percentageCalculation = aspectRatio / 100; | |
const tyreWallHeight = widthInMm * percentageCalculation; | |
const bothTyreWalls = tyreWallHeight * 2; | |
console.log(`Total tyre sidewall height is: ${bothTyreWalls.toFixed(2)}mm`); | |
return bothTyreWalls; | |
} | |
function getRimHeightInMm(rimHeightInInches) { | |
const rimHeightInMm = rimHeightInInches * mmInOneInch; | |
console.log(`Rim height is: ${rimHeightInMm.toFixed(2)}mm`); | |
return rimHeightInMm; | |
} | |
function getTotalWheelHeight(tyreWidth, aspectRatio, rimHeight) { | |
const rimHeightInMm = getRimHeightInMm(rimHeight); | |
const totalTyreWallHeight = getTyreHeightInMm(tyreWidth, aspectRatio); | |
return rimHeightInMm + totalTyreWallHeight; | |
} | |
function getWheelCircumference(wheelHeight) { | |
const wheelRadius = wheelHeight / 2; | |
return 2 * Math.PI * wheelRadius; | |
} | |
function outputReport() { | |
const wheelHeight = getTotalWheelHeight( | |
tyreWidthInMm, | |
tyreHeightInPercentage, | |
tyreRimHeightInInch | |
); | |
const circumference = getWheelCircumference(wheelHeight); | |
Object.keys(mockGearboxRatios).forEach(key => { | |
someRevs.forEach(revs => { | |
let wheelRpm = getWheelRpm(revs, mockGearboxRatios[key], finalRatio); | |
let wheelSpeed = speedInKmH(circumference, wheelRpm); | |
console.log(`Speed @${revs}RPM in ${key} gear: ${wheelSpeed.toFixed(2)}`); | |
}); | |
}); | |
} | |
function reduceRpm(rpm, ratio) { | |
return rpm / ratio; | |
} | |
function getWheelRpm(rpm, gearRatio, finalRatio) { | |
return reduceRpm(reduceRpm(rpm, gearRatio), finalRatio); | |
} | |
function speedInKmH(circumference, wheelRpm) { | |
return (wheelRpm * circumference * 60) / 1000000; | |
} | |
outputReport(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment