Individually Customised Pop-up Cards
Time limit3sMemory limit512 MB
For a pop-up card folding on parallel axes, find the minimum distance to move the contact point (Xp,0) so a matching second segment exists.
- Level
Hard8 of 10
- Topics
- Geometry, Math, Binary search, Implementation
- Solved
- No attempts yet
Problem
Laser cutters are easy to find now, so pop-up cards are worth designing again. This problem is the first version of the design tool.
The card is four flat polygons joined along four fold lines. The four fold lines stay parallel to each other at every moment of the fold. Call their common direction the direction. The whole structure can then be studied through its projection onto the plane , so the coordinate is dropped from here on.

The two pages of the card start at degrees to each other and are drawn as the positive axis and the positive axis. Both pages are infinitely large. The folding structure is one point of the first quadrant together with two line segments that join that point to each of the two pages. Closing the card rotates the two pages towards each other. When the two segments are chosen well, the structure folds flat without getting stuck at any moment, and at the end of the fold the two pages and both segments lie on one line. The pages and the segments must not bend, stretch, crease, or come loose from a fold line, and the angle between the pages never exceeds degrees.
The user draws one segment, from a point on the axis to a point of the first quadrant. The tool then looks for a second segment, from to a point with on the other page, so that the card still closes flat. When no such second segment exists, the tool moves the contact point on the axis by the smallest possible distance until at least one choice becomes available. Report that distance.
Input
The input holds several test cases. Each test case is one line with three integers , and separated by single spaces (, , ). They describe the segment the user drew, from to .
A line with three zeros separated by single spaces ends the input. There are at most test cases.
Output
For each test case print one line with the smallest distance that has to move, so that afterwards some segment from to some point with closes the card flat.
The set of distances that work can be open, so the value asked for is the smallest number such that working distances exist arbitrarily close to it. Print that value with exactly six digits after the decimal point.
Hint
The first example case, , , , is the one in the picture. Nothing has to move: the segment from to , dashed in the picture, gives a structure that folds flat.
In the third example case, , , , every distance strictly greater than and strictly smaller than gives a valid card, while itself gives none. Valid distances come arbitrarily close to , so the answer is .