The surface of a truncated cube consists of 6 octagons, and 8 equilateral triangles. Our truncated cube is parametrised by (h1, h2), where
- h1 refers to the distance between the center of the volume and the center of the octagons, and
- h2 refers to the distance between the center of the volume and the center of the triangles.
For
we get the special case of a cube, and for
we get a cuboctahedron.
Your task: Write a function which returns the volume V of the truncated cube as function of the heights h1 and h2. If the ratio h2/h1 violates the constraints
return the volume of the related special case (cube or cuboctahedron) instead.
Solution Stats
Problem Comments
4 Comments
Solution Comments
Show comments
Loading...
Problem Recent Solvers8
Suggested Problems
-
6711 Solvers
-
304 Solvers
-
Find third Side of a right triangle given hypotenuse and a side. No * - or other functions allowed
249 Solvers
-
16346 Solvers
-
Mysterious digits operation (easy)
315 Solvers
More from this Author4
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
Test Suite problems 1 and 2 seem to be incorrect. Did you mean to put parentheses around h1+abs(randn) and h1-abs(randn)?
I don't think that there is a problem.. For example test suite problem 1: h1 = abs(randn); h2 = sqrt(3)*h1; is a cube of random size. By adding + abs(randn), I violate the constraint h2 <= sqrt(3)*h1. If I put parentheses around h1+abs(randn), I have the same effect as before, just with another scaling of the random number that I added.. --> Result is the same: violation of the constraint for the cube. Same with test suit problem 2
Oh, sorry. I see now that these are the cases that are supposed to check that our code returns the correct responses when the inputs are "out of bounds". Thanks for pointing that out!
Tip: the 8 tetrahedra at the cube corners are not regular, but they have equilateral triangles as base.
PS: Kudos for the author, nice figures. It's so rare to find a problem with graphics at Cody. And sometimes a picture conveys much more than a long text.