views:

977

answers:

3

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.

+1  A: 

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
Yeah, that works for the cuboid, and is how I've done it there. But how would it work for the prism? Would it be correct to just shorten each of the lengths there ass well?
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.
Sekhat
@Killersponge: If the triangles were equilateral there would be no need to include the height of the prism as the question indicates.
AnthonyWJones
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 :)
Sekhat
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?
AnthonyWJones
a very small prism
Sekhat
This is the kind of prism we're talking about: http://z.about.com/d/math/1/5/J/F/Triangularprismr.gifFrom that figure, all I have access to is b, h and l. The rest will have to be calculated. I found http://www.mathopenref.com/isosceles.html, so I'm able to calculate the sides. But then what?
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
Sekhat
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.
jpalecek
@jpalecek hence comment further up
Sekhat
+2  A: 
jpalecek
Might be helpful to mention that the triangle is an isosceles triangle, two sides are equal in length. Meaning that the two angles near the baseline is the same. Nothing more is given, and it is possible to calculate it
+1. Nice illustration, better reasoning ;)
AnthonyWJones
+1  A: 

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.

AnthonyWJones