#P4545. Illuminated Screen Ratio

    ID: 17791 Type: Default 1000ms 256MiB

Illuminated Screen Ratio

Illuminated Screen Ratio

The projector located at the origin (0,0) emits a beam toward the positive y–axis. The beam is symmetric with respect to the y–axis and has a total angular spread of \(ang\) degrees, meaning its boundary rays make angles of \(90-\frac{ang}{2}\) and \(90+\frac{ang}{2}\) (in degrees) relative to the positive x–axis.

A projection screen is placed in the plane as a horizontal segment from \((x_s^1, y_s)\) to \((x_s^2, y_s)\) (thus parallel to the x–axis). In addition, there are \(n\) obstacles in the laboratory. Each obstacle is represented by a line segment (of zero thickness) with endpoints \((x_1,y_1)\) and \((x_2,y_2)\). Some obstacles are non–reflective (including the projection screen) and will absorb any light that strikes them, while others are reflective on both sides and will reflect the light according to the law of reflection (i.e. the angle of incidence equals the angle of reflection, with the reflection computed in \(\LaTeX\) as \(\mathbf{r}=\mathbf{d}-2(\mathbf{d}\cdot\mathbf{n})\mathbf{n}\), where \(\mathbf{d}\) is the incoming unit direction and \(\mathbf{n}\) is a unit normal of the obstacle’s line). All obstacles (and the screen) do not touch each other or the origin.

The light loses energy as it travels; specifically, the light vanishes after travelling a total distance of len.

The task is to determine the ratio of the length of the portion of the projection screen that gets illuminated by at least one ray to the total length of the projection screen.

Note: The light beam can reflect off reflective obstacles (if hit) but will stop upon striking a non–reflective obstacle (including the screen). The initial beam is a continuum of rays. For simulation purposes an acceptable approach is to sample many rays from the initial angular interval and simulate their paths (with at most a fixed number of reflections) until either they hit the screen or vanish.

inputFormat

The first line contains six numbers: x_s^1 x_s^2 y_s ang len n, where \(x_s^1\) and \(x_s^2\) (\(x_s^1 < x_s^2\)) are the x–coordinates of the two endpoints of the projection screen (the screen is at y–coordinate \(y_s\)), \(ang\) (in degrees) is the total beam angle, len is the maximum distance the light can travel, and \(n\) is the number of obstacles.

Then follow \(n\) lines, each describing an obstacle with five numbers: x1 y1 x2 y2 type. The obstacle is a segment connecting \((x1,y1)\) and \((x2,y2)\). If type is 0 the obstacle is non–reflective; if 1 it is reflective.

You may assume that no obstacle (or the screen) touches another or the origin.

outputFormat

Output a floating–point number representing the ratio of the illuminated length on the screen to the total length of the screen. An absolute or relative error of up to \(10^{-6}\) is allowed.

sample

-10 10 10 90 100 0
1.0