Greasy Fork is available in English.

Discussions » Development

Compute the volume of space inside a tire

§
Posted: 20-04-2021
Edited: 20-04-2021


tire_width_milliliters = 185
tire_ratio = 50
Wheel_diameter_inches = 14

//v is the volume in milliliters
//tire_width_milliliters is the width of the tire in millimeters,
//tire_ratio is the aspect ratio of the tire
//Wheel_diameter_inches is the diameter of the wheel in inches.

milliliters_volume = 3.141592653589793 + tire_width_milliliters ** 2 + tire_ratio + (tire_width_milliliters + tire_ratio + 2.540 + Wheel_diameter_inches) / 10000000


The code above returns 34278.1 but it should be 24090.1

I also know that using these values: 205, 60, 15 should output 39924.5 for the volume.

I'm having a problem trying to correctly convert that mathematical expression to programming language

wOxxOmMod
§
Posted: 20-04-2021
Edited: 20-04-2021

2,540 in the formula means 2540 in js. The comma is a thousands separator. BTW you can use Math.PI

§
Posted: 20-04-2021

@wOxxOm

Removing the comma doesn't change the result

wOxxOmMod
§
Posted: 20-04-2021

Also use * instead of + because in mathematics the lack of operation sign means it's the multiplication:

Math.PI * (tire_width_milliliters ** 2) * tire_ratio * (tire_width_milliliters * tire_ratio + 2540 * Wheel_diameter_inches) / 10000000
§
Posted: 20-04-2021

@wOxxOm
Thanks

That works on js, but on pyhton it returns 25455.6, I wanted this to work on python

wOxxOmMod
§
Posted: 20-04-2021

It works correctly in python here.

import math
tire_width_milliliters =  185
tire_ratio = 50
Wheel_diameter_inches = 14
print(math.pi * (tire_width_milliliters ** 2) * tire_ratio * (tire_width_milliliters * tire_ratio + 2540 * Wheel_diameter_inches) / 10000000)
§
Posted: 20-04-2021

Thanks, that worked!

Post reply

Sign in to post a reply.