Twirl Around
Time limit1sMemory limit128 MB
A bar inside a simple polygon rotates clockwise, pivoting on the wall whenever a new contact point appears; report the final position of one end, or the position when it jams.
- Level
Hard9 of 10
- Topics
- Geometry, Simulation, Implementation, Math
- Solved
- No attempts yet
Problem
A room on a flat plane is enclosed by a polygonal wall. Inside it a bar of length turns clockwise, like a twirling baton.
At the start one end of the bar (end A) sits at and the other end (end B) sits at . At that moment the bar touches the wall only at end A.
The bar turns around a single point where it touches the wall. As soon as another part of the bar reaches the wall, that new touching point becomes the center of rotation.
Find the coordinates of end A once the bar has turned radians clockwise in total.
The bar can also get stuck along the way. That is the state where no touching point lets it turn clockwise any further. The motion ends there, and the answer is the position of end A at that moment.
You may assume that when the length changes by with , the final coordinates change by no more than .
Input
The input holds several datasets. There are at most 100 of them. The end of the input is marked by 0 0 0.
Each dataset has the following format.
L R N
X1 Y1
X2 Y2
...
XN YN
is the length of the bar. The bar turns radians unless it gets stuck first. is the number of vertices of the polygonal wall.
The vertices of the polygon are given in counter-clockwise order. The polygon is simple, so its border never crosses or touches itself.
, and are integers, and and are decimal fractions. The ranges are as follows.
- ,
- ,
Output
For each dataset, print the final position of end A on one line. The judge compares the output exactly, so write the coordinates as integers: multiply and by 1000, round each to the nearest integer, and print the two integers separated by one space.
In the test data, and stay at least away from a rounding boundary, that is from any integer plus , so the rounded value is uniquely determined.