#P6711. Constructing a Convex Polygon
Constructing a Convex Polygon
Constructing a Convex Polygon
You are given the lengths of all the edges of a convex polygon (which is assumed to be cyclic). Your task is to reconstruct the polygon by computing the coordinates of its vertices.
Assume that the polygon is inscribed in a circle. Let the polygon have n sides with lengths L1, L2, …, Ln. Since the polygon is cyclic, each side subtends a central angle given by:
\(\theta_i = 2\arcsin\left(\frac{L_i}{2R}\right)\)
where \(R\) is the circumradius. The sum of all these angles must equal \(2\pi\):
\(\sum_{i=1}^{n}2\arcsin\left(\frac{L_i}{2R}\right)=2\pi\)
Your task is to determine the unique \(R\) (using binary search) and then compute the vertices coordinates as follows:
- Choose the first vertex at \((R, 0)\).
- The angle for the i-th edge is \(\theta_i\). Then, the angle for vertex \(i\) (starting from 0 for the first vertex) is the cumulative sum \(\alpha_i = \sum_{j=1}^{i} \theta_j\) with \(\alpha_0=0\).
- The coordinates of the i-th vertex are \((R\cos\alpha_i, R\sin\alpha_i)\).
Output the vertices with 6 decimal places of precision.
inputFormat
The first line contains an integer n (\(n \ge 3\)), the number of sides of the polygon.
The second line contains n positive real numbers \(L_1, L_2, \dots, L_n\) representing the lengths of the sides.
outputFormat
Output n lines. Each line should contain two real numbers representing the \(x\) and \(y\) coordinates of a vertex of the polygon in order. The coordinates should be printed with 6 decimal places.
sample
3
3 4 5
2.500000 0.000000
0.709150 2.397327
-2.500000 0.000000
</p>