#P4353. Expected Visible Spots from a Dice in a Box

    ID: 17599 Type: Default 1000ms 256MiB

Expected Visible Spots from a Dice in a Box

Expected Visible Spots from a Dice in a Box

You have trapped a hornet inside a 5×5×5 box that rests on a table. Inside the box, a standard 1×1×1 dice lies on the table with its bottom face centered at the origin. The dice has its two opposite corners at \( (-0.5,-0.5,0) \) and \( (0.5,0.5,1) \). Its faces bear spots as follows:

  • Top face: 5 spots
  • South face: 1 spot
  • East face: 3 spots
  • North face: 6 spots
  • West face: 4 spots
  • Bottom face: 2 spots (irrelevant)

The box is specified by the coordinates of its bottom face – a 5×5 square lying on the \(xy\)‐plane. (Note that the box extends vertically from \(z=0\) to \(z=5\).)

The hornet is uniformly randomly located in the volume of the box except the interior of the dice. A spot on the dice is visible to the hornet if the line segment connecting the center of that spot and the hornet’s position does not pass through the interior of the dice. Since the dice is convex and opaque, a given face (with center \(C\) and outward unit normal \(\mathbf{n}\)) is visible if and only if the hornet lies in the open half–space defined by

[ \mathbf{n} \cdot (\mathbf{P} - C) > 0. ]

For the dice the conditions become:

  • Top face: \(z > 1\)
  • South face: \(y < -0.5\)
  • East face: \(x > 0.5\)
  • North face: \(y > 0.5\)
  • West face: \(x < -0.5\)

Since the hornet is uniformly distributed in the accessible volume, the expected number of visible spots is computed as the weighted sum of the probability that each face is visible multiplied by its number of spots. Let \(V_f\) be the volume of the hornet positions (inside the box and outside the dice) from which face \(f\) is visible. The total accessible volume is \(125-1=124\). Note that for these half–space conditions the dice itself is not in the region (except for the top face it is irrelevant, and for the other four faces the dice lies completely on the opposite side).

Since the box is a vertical extrusion of the given bottom square (area 25), the volume of points satisfying a condition of the form \(x > c\) (or \(xc,\; y1\) is \(25\times(5-1)=100\). Thus, the expected number is:

[ E = \frac{5\cdot100 + 5\cdot\Bigl(1\cdot A_{south} + 3\cdot A_{east} + 6\cdot A_{north} + 4\cdot A_{west}\Bigr)}{124}, ]

where \(A_{south}\) is the area of the bottom square with \(y 0.5\), \(A_{north}\) with \(y>0.5\), and \(A_{west}\) with \(x<-0.5\), computed by clipping the square with the appropriate half–plane.

Your task is to compute and print the expected number of visible spots (with at least 6 decimals of precision) given the 4 vertices of the bottom side of the box.

inputFormat

The input consists of 4 lines. Each line contains two real numbers representing the coordinates \(x\) and \(y\) of one vertex of the bottom square of the box, given in either clockwise or counterclockwise order.

outputFormat

Output the expected number of spots visible to the hornet as a real number with at least 6 digits after the decimal point.

sample

-1 -1
4 -1
4 4
-1 4
10.887097