Polygon Revolution
Time limit2sMemory limit512 MB
Given a convex polygon and an axis line that may cut through it, find the volume of the solid formed by revolving the polygon around the line, within absolute error 0.1.
- Level
Medium7 of 10
- Topics
- Geometry, Math, Implementation, Brute force
- Solved
- No attempts yet
Problem
Given a convex polygon with vertices and a line on a 2-dimensional plane. You can generate a 3-dimensional solid of revolution by the revolution of the convex polygon around the axis . Calculate the volume of this solid.
When the axis is an external line of the convex polygon, the task is much easier, because the following theorem helps. However, note that the axis may intersect the convex polygon.
The second theorem of Pappus: The volume of a solid of revolution generated by the revolution of a lamina about an external axis is equal to the product of the area of the lamina and the distance traveled by the lamina's geometric centroid .

Figure 5: Sample revolutions
Input
The first line of the input is a positive integer , the number of test cases. The first line of each test case is a positive integer (), the number of vertices of the convex polygon. Then lines follow. The -th () line contains two real numbers () and (), the coordinates of the vertices of the convex polygon in clockwise order. Finally, three real numbers () represent the equation of the axis .
Output
The output consists of lines, one line for each test case. Each line contains one real number, the volume of the solid of revolution, with an error not greater than .