Calculating the volume of a restaurant take-away box that is circular on the bottom and square on the top Having a bit of a problem calculating the volume of a take-away box:



I originally wanted to use integration to measure it by rotating around the x-axiz, but realised that when folded the top becomes a square, and the whole thing becomes rather irregular. Since it differs in circumference I won't be able to measure it like I planned.

Is there any method or formula that can be used to measure a shape like this, or do I just have to approximate a cylinder and approximate a box and add those two together?
A different approximation could be to take the cross-section at each height not as a linear interpolation between top and bottom surface, but as squares with rounded corners. This fits the photograph more closely, as the linear interpolation approach has a discontinuity in the radius of curvature at the bottom: The point that at the top is an edge of the square is modelled a crease along the entire side, while in the photograph, no such crease can be seen.



If we take the cross-section to have the above shape of a rounded square, we can calculate its area by using the formulas for circles and rectangles:

$$A = \pi \cdot r^2 + 2 \cdot a \cdot b - b^2$$

Using $b=a-2\cdot r$, we can eliminate that variable:

$$A = a^2 + (\pi -4) \cdot r^2$$

Now we assume that those variables vary linearly between top and bottom: $r$ goes from $r_0$ at the bottom to $0$ at the top, and $a$ goes from $2r_0$ at the bottom to $a_0$ at the top, giving us:

$$r(h) = \left(1-\frac{h}{h_0}\right)\cdot r_0$$

$$a(h) = \left(1-\frac{h}{h_0}\right)\cdot 2r_0 + \frac{h}{h_0} \cdot a_0$$

and thus:

$$A(h) = \left(1-\frac{h}{h_0}\right)^2 \cdot \pi \cdot r_0^2 + \left(1-\frac{h}{h_0}\right) \cdot \frac{h}{h_0} \cdot 4 \cdot r_0 \cdot a_0 + \left(\frac{h}{h_0}\right)^2 \cdot a_0^2$$

or, better ordered for integration:

$$A(h) = \pi \cdot r_0^2 + \frac{h}{h_0} \cdot \left( 4\cdot r_o \cdot a_0 - 2 \cdot \pi \cdot r_0^2 \right) + \left(\frac{h}{h_0}\right)^2 \cdot \left( a_0^2 - 4\cdot r_0 \cdot a_0 + \pi \cdot r_0^2\right) $$

Which gives us then:

$$ V = \int_0^{h_0} A(h) \mathrm{d}h= h_0 \cdot \pi \cdot r_0^2 + \frac{1}{2} \cdot \frac{h_0^2}{h_0} \cdot \left( 4\cdot r_o \cdot a_0 - 2 \cdot \pi \cdot r_0^2 \right) + \frac{1}{3}\cdot\frac{h_0^3}{h_0^2} \cdot \left( a_0^2 - 4\cdot r_0 \cdot a_0 + \pi \cdot r_0^2\right)$$

$$=h_0\cdot\left(\frac{1}{3}\pi r_0^2 + \frac{2}{3} r_0 a_0 + \frac{1}{3} a_0^2\right)$$

And here is a quick render of what this looks like in 3d:



This result can be obtained classically without any integrals as well, using only the formulas for the volume of conic solid and for cuboids. To do this, we split the solid into nine parts:



The central, yellow part is simply a square pyramid, and has a volume of $\frac{1}{3}\cdot h_0\cdot a_0^2$. The four magenta pieces are oblique cones with a quarter-circle as base. Again, using the formula for conic solids, their volume is each $\frac{1}{12}\cdot h_0\cdot\pi\cdot r_0^2$

And the four cyan pieces are irregularly shaped tetrahedrons, but we can determine their volume by adding a few pieces to see how they fit into a cuboid of the measurements $a_0\times r_0 \times h_0$:



In the more general case of $\frac{a_0}{2} \neq r_0$, there will be a fourth green piece needed (which would go in front and block our view of everything). However, the green pieces together form a prisma of height $a_0$ and a top surface area of $\frac{1}{2} \cdot r_0 \cdot h_0$, and the two blue-grey pieces are two pyramids with height $h_0$ and rectangular bases of size $\frac{1}{2} a_0 \times r_0$. Therefore, the volume of the tetrahedron is:

$$a_0 \cdot h_0 \cdot r_0 - a_0 \cdot \frac{1}{2} \cdot r_0 \cdot h_0 - 2 \cdot \frac{1}{3} \cdot h_0 \cdot \frac{1}{2} a_0 \cdot r_0 = \frac{1}{6} h_0 \cdot r_0 \cdot a_0$$

Putting it all together, we get the volume as:

$$V=\frac{1}{3}\cdot h_0\cdot a_0^2 + 4\cdot \frac{1}{12}\cdot h_0\cdot\pi\cdot r_0^2  + 4 \cdot \frac{1}{6} h_0 \cdot r_0 \cdot a_0$$
$$=h_0\cdot\left(\frac{1}{3}\pi r_0^2 + \frac{2}{3} r_0 a_0 + \frac{1}{3} a_0^2\right)$$

A more smooth model along the same lines would be to interpolate superellipses between the bottom and top, which similarly would give a creaseless change in the radius of curvature beneath the corners. However, superellipse areas have a formula involving the gamma function, and are therefore not easy to integrate again to get a volume.
A more general approach
Discussions in the comments have identified two conditions which should be fulfilled for a valid model of the box given that it is constructed from cardboard:

The lateral surface has a Gaussian curvature of 0, or more informally, can be unrolled into a flat surface without additional cuts
If the radius of the bottom circle or the side length of the top square are set to 0, the formula should turn into the known formulas for the volume of a pyramid or cone, respectively. (This actually follows from the first condition, because those shapes are the only ones fulfilling it in this degenerate case)

A class of objects which automatically fulfil these conditions are prismatoids, which are polyhedral solids whose vertices lie on two parallel planes:

Their lateral faces consist of triangles or trapezoids, which are automatically flat, and since there are no vertices in between the top and bottom surface, and therefore any lateral face can only connect to two neighbouring lateral faces, we can also unfold its lateral surface into a flat shape by &quot;hinging&quot; along the edges.
The prismatoid model can also be used as approximation for not polygonal top and bottom surfaces, by approximating them by increasingly fine polygons. For example, the model used by Aretino and J. M. can be approximated by a prismatoid by creating vertices at top and bottom positions corresponding to evenly spaced values of $\theta$. The model examined in my other answer can be approximated by taking evenly spaces vertices along the circle and connecting each to the closest corner of the square.
The good thing about prismatoids is that they have a very simple formula to calculate their volume, which requires one to know only the values of the area of the cross-sections at the top ($A_1$), bottom ($A_3$) and at half height ($A_2$). Then, the total volume of the solid is:
$$V= \frac{h}{6}(A_1 + 4 A_2 + A_3)$$
Since $A_1$ and $A_3$ are fixed by the nature of the problem as $\pi\cdot r^2$ and $a^2$, respectively, the choice of model for the shape of the solid is merely a choice of what value to assume for $A_2$.
In fact, by following the second condition to its conclusion, it can be shown that any model using the prismatoid approach must have in the end a volume formula of the shape:
$$V = h\left(\frac{1}{3}\pi r^2 + \gamma a r + \frac{1}{3}a^2\right)$$
In which there is only the choice of $\gamma$ remaining as free variable. While any particular model can then make additional claims about why it, and therefore its choice of $\gamma$ is the most valid one, as a more general overview the question can be posed: What is the possible valid range of $\gamma$? Or equivalently, what is the possible range for $A_2$?
As it turns out, the maximum $A_2$ is actually the one given by my other answer, as the described shape is actually the convex hull of the points on the circle and the square (something I'll state without proof because it should be easy enough for yourself to convince yourself of that fact), which has a $\gamma$ of $\frac{2}{3}$.
And for the prismatoid with the minimal $A_2$ (excluding self-intersecting or twisted models, because they don't agree with the problem as posed), I nominate this one:

And its cross-section looks like this:

I can't prove that connecting each circle point to the closest midpoint of the square gives the least area, but it seems likely, as moving any one connecting appears to increase the cross-section.
The area, as can be shown by simple calculation of the square and circle segment areas, is:
$$A_2 = \frac{1}{4}a^2 + \frac{1}{\sqrt{2}} a r + \frac{\pi}{4} r^2$$
Plugging this into the volume formula gives:
$$V_{min} = h\left(\frac{1}{3}\pi r^2 + \frac{\sqrt{2}}{3} a r + \frac{1}{3}a^2\right)$$
With therefore a minimal $\gamma$ of $\frac{\sqrt{2}}{3}$ and a maximal $\gamma$ of $\frac{2}{3}$, we can ask the question:
How much does choosing the model then actually matter?
By taking a &quot;cube&quot; box as example with $h = 1$, $a=1$ and $r=\frac{1}{2}$, we can calculate the volumes and their differences:
$$\Delta V = V_{max} - V_{min} = \left(\frac{1}{12}\pi + \frac{2}{3}\right) - \left(\frac{1}{12}\pi + \frac{1}{3\sqrt{2}} + \frac{1}{3}\right) = \frac{2-\sqrt{2}}{6}$$
Or, in floating point units:
$$V_{max} \approx 0.928466$$
$$V_{min} \approx 0.830835$$
$$\Delta V \approx 0.097631$$
Or in other words, the choice of exact model changes the result in volume by at most 10%.
There is technically a &quot;best&quot; model among all possible choices of prismatoids, which is the one whose lateral surface is unrolled into the closest approximation of a circle ring sector, which is the lateral net of a truncated cone, the shape of the takeaway box before the top is folded, and a deformation of the paper which does not tear it has to preserve the net. However, I will not attempt to find which $\gamma$ this then results in, and only, based on the shapes of the models examined already, assume it is rather close to $\frac{2}{3}$.