Shoring Up the Levees

Time limit1sMemory limit128 MB

Summary
Given a convex quadrilateral, order its four corner triangles by area and print each triangle's area and perimeter rounded to three decimals.
Level

Medium4 of 10

Topics
Geometry, Sorting, Math, Implementation
Solved
No attempts yet

Problem

The tiny country of Waterlogged is protected by a ring of levees that form a convex quadrilateral, as shown below.

The quadrilateral is given by its four corner vertices. Two more levees run along the diagonals of the quadrilateral; together with the outer ring they divide the country into four triangular quadrants. Each quadrant is named by the pair of neighbouring vertices on its outer edge — for example, the quadrant shown below has its outer edge between (x1,y1)(x_1,y_1) and (x2,y2)(x_2,y_2).

Because the two diagonals cross at a single interior point, the quadrant on a given outer edge is exactly the triangle bounded by that outer edge and the two diagonal segments running from its two endpoints to the crossing point.

Waterlogged floods often, so its levees must be reinforced, but the country is poor and has limited resources. It wants to reinforce the quadrants in order of area: the largest area first, then the second largest, then the third, and the smallest last. For each quadrant, from largest area to smallest, report that quadrant's area and the total length of the levees around it (its perimeter).

Input

The input contains several data sets. Each data set is a single line of eight real numbers:

X1 Y1 X2 Y2 X3 Y3 X4 Y4

giving the four vertices in order. The four points are guaranteed to form a convex quadrilateral in this order — no concave corners and no crossing edges. Every number lies in the range −1000.0-1000.0 to 1000.01000.0 inclusive. No quadrant has an area or a perimeter smaller than 0.0010.001. The input ends with a line of eight 0.00.0 values, which is not processed.

Output

For each data set, print a single line of eight real numbers:

A1 P1 A2 P2 A3 P3 A4 P4

where AkA_k and PkP_k are the area and perimeter of the kk-th quadrant. List the quadrants from largest area to smallest, so A1A_1 is the largest area. If two quadrants have the same area after rounding to three decimal places, print the one with the larger perimeter first. Print every value rounded to exactly three decimal places, separated by single spaces. Do not print any blank lines between outputs.

Examples1

  1. Example 1

    Input
    1 2 1 5 5 2 2 0
    3.5 2.2 4.8 -9.6 -1.2 -4.4 -8.9 12.4
    0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
    
    Expected output
    5.100 11.459 3.400 9.045 0.900 6.659 0.600 4.876
    44.548 38.972 21.982 25.997 20.342 38.374 10.038 19.043