Thursday, April 28, 2011

Calculating volumes of hollow three dimensional geometric objects

We've gotten a homework assignment in Java, which relates to inheritance. I don't have a problem with the programming in itself, but I'm a bit unsure about some of the math, and would like confirmation/corrections from someone a bit more knowledgable.

The assignment starts with a abstract class, GeometricObject, which is extended into three two-dimensional objects. A rectangle, a circle and a triangle. Those three are then extended into a cuboid for the rectangle, a cylinder and a sphere for the circle, and the triangle into a triangular prism.

Each of these three-dimensional objects are hollow, and has a defined thickness and is made of a special metal, so we are to calculate their weight. And herein lies the problem, since I'm a bit unsure as to how I find the "inner volume" on some of them.

  • Cuboid: Here I assume that I can just subtract 2 * thickness from the width, height and depth, and then everything looks fine.
  • Cylinder: Subtract thickness from the radius making up the base, and 2*thickness from the height
  • Sphere: Subtract thickness from the radius
  • Prism: This is where I'm a bit stuck. Each object gets passed a baseline, height of the triangle, and the height for the entire prism. How can I use this in order to find the "inner prism" representing the inner volume?

Update: Forgot to mention that when creating the object, we specify the outmost sizes, and the hollow part is inside of this. The other way around is not allowed.

Update again: The triangle is an isosceles triangle.

Update yet again: Mixed up radius and diameter for the circular. Corrected now.

From stackoverflow
  • Get the volume of the shapes as if they were not hollow, then, get the volume of the hollow are only (Shape - Thickness)

    subtract full volume from hollow volume to get the actual volume of the metal.

    Example:

    Cube:

    Full Volume: Height * Width * Depth
    
    hollow volume: (Height - Thickness) * ( Width - Thickness ) * ( Depth - Thickness)
    
    Volume of the metal used: Full Volume - hollow Volume
    

    Work out the weight from the volume of the metal used..


    Assuming your prism is triangular and the triangle is equilateral that the base line is the base of the triangle and the height is from the baseline to the opposite point (and the height line is at an right angle from the baseline).

    Then the full volume would be

    fv = (1/2 * baseLine * triangleHeight) * prismHeight
    

    the hollow volume would be

    hv = (1/2 * (baseline - thickness) * (triangleHeight - thickness)) * (prismHeight - thickness)
    


    After reading you comment to jpaleck, it would seem your baseline is the Hypotenuse of the triangle, (the longest line), the above should still hold true with that.


    Sekhat : Assuming your prism is triangular and the triangle is equilateral. Then the full volume would be fv = (1/2 * baseLine * triangleHeight) * prismHeight, the hollow volume would be (1/2 * (baseline - thickness) * (triangleHeight - thickness) * prismHeight
    Sekhat : you may have to multiple thickness by two so that you account for the changes of the line lengths on each side. As a thickness of 10, when drawing a shape shortened by 10 in each dimension actually only gives a metal thickness of 5 all the way around.
    AnthonyWJones : @Killersponge: If the triangles were equilateral there would be no need to include the height of the prism as the question indicates.
    Sekhat : Indeed. Though the above formula is sound anyway, Assuming the baseline is one side of the triangle and the triangle height is from the center of that line to the point opposite it.
    Sekhat : I've edited this answer alot now, but that should be it :)
    AnthonyWJones : I'm no maths wiz but I'm fairly sure you can't calculate the inner baseline so simplistically. Each corner is a three-way mitre, the specified height will modify the available inner baseline. Imagine if the height of the prism in total is only 3 * thickness, what would the inner volume look like?
    Sekhat : a very small prism
    Sekhat : you don't need to calculate the sides if it's just the volume, all you want is the area of the triangle (which is half the area of the tightest rectangle you can fit round) times it's overall height then shrink the values your using. Read my answer again plus the comment about multiplying thickness
    jpalecek : The problem with your approach is that when you put metal of thickness h inside the triangle, the tightest rectangle holding the triangle will not have sides smaller by h, but by more than 2*h.
    Sekhat : @jpalecek hence comment further up
  • I think you cannot get this result from the data you have (baseline length & triangle height). You have to get other information, like location of the points or the angles at the baseline.

    Edit: since the triangle is isosceles:

    As AnthonyWJones already pointed out, the inner triangle is similar to the outer triangle. Therefore, the only thing you need is find the ratio between the two.

    sketch

    You can find it easily from the height. Since triangles CQP and ACS are similar

    h2 : |PQ| = |AC| : |AS|
    

    where

    |PQ| = h1 (= the thickness of the metal)
    |AC| = sqrt(base^2/4+height^2)
    |AS| = base/2
    

    Then, you compute h2 and the ratio r = (height - h1 - h2)/height is the ratio between the two triangles. The area of the inner triangle is then r^2 * area of the outer triangle.

    AnthonyWJones : +1. Nice illustration, better reasoning ;)
  • One thing you know about the inner prism is that it will have the same ratios as the outer prism. In other words given the height of the inner prism you can calculate the inner base length and from there the volume.

    You know the base will have 1 unit thickness. So that leaves calculating the distance from the pinnacle of the inner prism to the pinnacle of the outer prism.

    That distance is the hypontenuse of a right angled triangle. The angles in the triangle are known since they are function of the base length and height. One side of the triangle is of thickness length being the perpendicular from the inner edge at the inner pinnacle to the outer edge. (The final side of the triangle is where that perpendicular intersects the outer edge up to the outer pinnacle).

    This is enough info to use standard trig to caclulate the hypotenuse length. This length plus 1 thickness (for the base) subtracted from the original height gives you the inner height. The ratio between the inner and outer heights can be applied to the base length.

    There a probably cleverer ways to do this but this would be my common bloke approach.

0 comments:

Post a Comment