calculating volume using fractions (decimals) and getting strange results for filler program

StackOverflow https://stackoverflow.com/questions/20512197

Pregunta

So I'm trying to write a program that involves very small volumes, such as, for instance, a .5-cm box, .5 cm on each side.

1/2*1/2*1/2=1/8 cm^3, right?

But this seems wrong, because 1/8 (.125) is a much smaller number than 1/2 (.5). By way of comparison, let's say we look at the mm instead:

.5 cm = 5 mm

5*5*5=125 mm^3. This seems right, because 125 is way bigger than 5.

Sorry for the idiotic question, but I'm trying to write a program involving this and the math is hanging me up, and it seems like an obvious answer that I'm hoping someone can clarify it for me. I've Googled around for the answer but can't find it!

¿Fue útil?

Solución

Keep in mind, you are talking about 3D volumes not simple distances. For an intermediate example that is easier to visualize, consider doubling the height and width of a rectangle. Twice as wide and twice as high, means four times the area. With cubes, the difference is eight times. As a result, using mm instead of cm means that a 1/2 by 1/2 by 1/2 cm cube is equivalent to a 10 / 2 by 10 / 2 by 10 /2 mm cube. Compared to a cubic centimeter (cm3), the cube is 1-eight the volume of the larger cubic centimeter. The same cubic centimeter measured using millimeters is a 10 * 10 * 10 mm3 cube -- a 1000 mm3 cube. The smaller cube is a 125 mm3 cube which is still 1-eighth the volume of the 1 cm3/ 1000 mm3 cube.

Otros consejos

The problem is that you are comparing 3-dimensional space to just a length which runs in 1-d.

In other words, you are trying to compare volume (measured in cm^3 or cubic cms) with a single length or side of the cube (measured in cms). The value .125 cubic centimeters doesn't mean anything when you just compare it to a length of .5 cms.

If instead of a cube you had a 3-d shape where the sides were .5 cm x .4 cm x .3 cm, then the volume of that would be .06 cms^3 which would be something that you could directly compare.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top