Spherical Mirrors
Time limit1sMemory limit128 MB
Simulate a laser reflecting off multiple spheres in 3D using mirror-reflection geometry and report the final reflection point.
- Level
Medium6 of 10
- Topics
- Geometry, Simulation, Math
- Solved
- No attempts yet
Problem
There are spherical mirrors in three-dimensional space.
A laser is fired from in the direction . The laser always travels in a straight line.
Suppose a laser fired from a point is reflected at a point on a spherical mirror. Let be a point that lies outside the mirror and on the straight line joining the mirror's center and . Then the laser is reflected in a direction that satisfies the following condition:
(1) lies in the plane determined by , , and , and .
Write a program that finds the position of the point at which the laser is reflected for the last time.
Input
The first line contains the number of test cases . For each test case, the first line contains the number of spherical mirrors . The second line contains the direction , , in which the laser is fired, separated by spaces.
Each of the next lines contains four integers , , , describing a spherical mirror whose center is and whose radius is .
The distance between any two spherical mirrors is at least . The point lies outside every spherical mirror and is at least away from each of them.
The laser is reflected by the spherical mirrors at least once and at most five times. Moreover, the angle of reflection (that is, , which equals ) is always smaller than .
Output
For each test case, output the coordinates of the last reflection point, separated by spaces. Every coordinate is rounded at the fourth decimal place and printed to three decimal places.