Model Rocket Height

Time limit1sMemory limit128 MB

Summary
Given angle measurements from two observers with fixed geometry, compute the rocket's smoke-point height using 3D line intersection, or flag disqualification or measurement error based on given thresholds.
Level

Medium6 of 10

Topics
Geometry, Math, Implementation
Solved
No attempts yet

Problem

Two observers, A and B, stand on a baseline along one edge of a flat test field. They are D feet apart. The launch platform is the same distance from A and B, and is L feet away from the baseline. The measuring device used by A is HA feet above the launch platform, and the device used by B is HB feet above the launch platform.

After a rocket is launched, near the top of its flight it deploys a parachute and emits a puff of smoke. Each observer measures the elevation angle to the smoke and the azimuth angle of the sight line. The elevation angle is measured above the horizontal. The azimuth angle is measured counter-clockwise from the baseline direction from A to B to the vertical plane containing the sight line.

If the smoke point is on the wrong side of the baseline, or outside the two lines through A and B perpendicular to the baseline, the flight is disqualified. In this problem, the angle ranges determine that condition.

Each sight line determines a vertical plane, and the two vertical planes meet in a vertical line. Each sight line intersects that vertical line at one point. If the distance between those two points is more than ERRDIST feet, the measurement is considered erroneous and the flight is rejected. Otherwise, compute the midpoint of those two points. The required rocket height is the distance, in feet, from the launch platform to that midpoint.

Input

The first line contains the number of data sets N, where 1 <= N <= 1000.

The second line contains D, L, HA, HB, and ERRDIST, in that order, as real numbers. These values are measured once at the beginning of the day and are used for every launch.

Each of the next N lines describes one launch and contains α, β, γ, and δ, in that order, as real numbers. α is the elevation angle measured by left observer A, β is the elevation angle measured by right observer B, γ is the azimuth angle measured by A, and δ is the azimuth angle measured by B. All angles are in degrees.

Output

For each launch data set, output one line.

If α, β, and γ are not strictly between 0 and 90 degrees, or if δ is not strictly between 90 and 180 degrees, output DISQUALIFIED.

Otherwise, if the distance between the two points where the sight lines meet the vertical line is more than ERRDIST feet, output ERROR.

Otherwise, output the rocket height above the launch platform, rounded to the nearest foot.

Examples1

  1. Example 1

    Input
    4
    100.0 300.0 5.25 2.92 5.00
    40.1 36.2 35.3 151.6
    64.9 71.1 15.7 160.1
    44.9 41.2 33.1 152.5
    44.9 41.2 33.1 52.5
    Expected output
    50
    ERROR
    58
    DISQUALIFIED