2D Coordinate Conversion
Time limit1sMemory limit512 MB
For each test case, convert a point between Cartesian (x, y) and polar (r, theta) coordinates, with theta in the range [0, 2pi).
- Level
Easy2 of 10
- Topics
- Math, Implementation
- Solved
- No attempts yet
Problem
There are several ways to express the position of a point in two-dimensional space. The Cartesian coordinate system, which is widely used, expresses a point's position with a one-dimensional position along the x-axis and the y-axis. This problem introduces another way to express a point's two-dimensional position. For convenience, let the coordinates of point in the Cartesian coordinate system be .
- Polar coordinate system: Let the length of be , and let be the angle measured counterclockwise from the positive x-axis to . Then the coordinates of are . (; ) However, if , is defined as .
Given the coordinates of in either the Cartesian or the polar coordinate system, convert them to coordinates in the other system.
Input
The first line contains the number of test cases .
Each test case consists of 2 lines, starting from the second line.
The first line of a test case contains the coordinate system number of the coordinates to convert. 1 is the Cartesian coordinate system, and 2 is the polar coordinate system.
The second line of a test case contains two real numbers and , given to eight decimal places, that represent the coordinates to convert. is in the Cartesian case and in the polar case.
Output
For each test case, print on one line two real numbers that represent the converted coordinates.
An absolute or relative error of up to is allowed.