Spherical Coordinates

Problem #25

Tags: geometry

Who solved this?

Previous:Cylindrical Coordinates Next:Scalar Projection


Now that we have explored Polar Coordinates and Cylindrical Coordinates, let's look at another common three-dimensional coordinate system - Spherical Coordinates.

To locate a point in the Spherical coordinate system, let's imagine we are standing at the origin of a three-dimensional coordinate system. With the positive z-axis pointing "upwards", we face towards the positive x-axis and then rotate θ degrees counter-clockwise. We then point our finger straight up so that it is parallel with the z-axis, then lower it until it makes an angle of φ degrees. The point we are looking for is now ρ units away from the origin in the direction we are pointing.

Spherical Coordinates

Note that while the image uses r to denote distance, we will use ρ in this problem.

So θ is the direction we are facing on the x-y plane (called the azimuth), while φ is the angle from the positive z-axis (called the inclination), and a single point is defined in the format (ρ, θ, φ).

Note that while this naming convention is typical for math applications, it is common in other applications (such as physics) to use φ to represent the azimuth and θ to represent the inclination. For consistency, this site will use θ to represent the azimuth and φ to represent the inclination.

Problem Statement

Input Data
First line will be Q, the quantity of testcases.
Q lines will then follow with a single testcase each, either in the format C x y z or S ρ θ φ, where C or S indicate if the values are in Cartesian or Spherical coordinates, and the following three values are the coordinates of the point.

Answer
Should consist of 3 * Q space-separated values, corresponding to the given coordinates after being converted into the other coordinate system.
Error should be no more than 1e-6

Example

input data:
5
C 0 3 0 
C 4.5 -6.7 8.9
S 3 456 0
S 4.5 -6.7 8.9
S -9.8 7.6 -5.4

answer:
3 90 90 12.014574 -56.113041 42.203209 0 0 3 0.691442 -0.081226 4.445819 0.914160 0.121975 -9.756507
You need to login to get test data and submit solution.