Distance in Cone Coordinates
Time limit2sMemory limit128 MB
Given two points on a cone specified by distance from apex and angle, compute the shortest path length that stays on the cone's surface.
Problem
A right circular cone has its base of radius r on the plane z = 0. The center of the base is (0, 0, 0), and the apex is (0, 0, h), so the height is h.
A point p on the cone is represented by cone coordinates (d, A). Here d is the distance from the apex (0, 0, h) to p. A is the angle between the plane y = 0 and the plane passing through p, (0, 0, 0), and (0, 0, h), measured counterclockwise from the positive x-axis direction, with 0 <= A < 360.
Because the point is always on the conical surface, d is the ordinary three-dimensional distance from the apex to p.
Given two points p1 = (d1, A1) and p2 = (d2, A2) in cone coordinates, find the shortest distance from one point to the other when the path must stay on the conical surface.
Input
The input consists of multiple test cases. Each test case is given on one line as six real numbers r, h, d1, A1, d2, A2.
Output
For each test case, output one line containing the shortest distance between the two points along the conical surface, rounded to two digits after the decimal point.