UVa 10772 - Rose windows

10772 - Rose Windows

 * http://acm.uva.es/p/v107/10772.html

Summary
A regular polygon with $$n$$ vertices ($$n$$ is an even number) is inscribed in a circle of radius $$r$$. Then every two vertices of the polygon are joined with straight lines, and the resulting regions are colored in $$n/2$$ different colors as shown in figures.

Determine the area of the $$k$$-th region. Regions are numbered from 1, starting from the innermost region.

Explanation
If you study the figures carefully, you'll see that the boundary of every regions (except the outermost one) is a regular polygon with $$n$$ vertices, and its vertices are intersections of chords of the polygon.

More formally, let $$V_i$$ be the i-th vertex of the polygon: $$V_i=(r \cos\frac{2 \pi i}{n}, r \sin\frac{2 \pi i}{n})$$. And let $$1 \le k < \frac{n}{2}$$ be the number of region. Then the $$j$$-th vertex of the boundary of $$k$$-th region is the intersection of line segments $$V_{j} V_{j+(n/2)-k}$$ and $$V_{j+1} V_{j+1+(n/2)-k}$$.

The area of $$k$$-th region is the difference between inner areas of boundaries of $$k$$-th and $$k-1$$-st regions.

Area of regular polygon can be computed, if you know coordinates of its center O and one of vertices V. It equals $$\frac{n}{2} (OV)^2 \sin\frac{2 \pi}{n}$$

Input
14 10 8 1 10 8 2 10 8 3 10 8 4 50 12 1 50 12 2 50 12 6 100 40 1 100 40 2 100 40 3 100 40 10 100 40 15 100 40 19 100 40 20

Output
48.5281 117.1573 117.1573 31.3166 538.4758 1471.1432 353.9816 193.7897 576.5974 945.2074 2462.3319 1878.1616 576.5974 129.0335