This page is still under construction.

Parts of this page are still being built. What you see may change.

Reflections

Time limit1sMemory limit128 MB

Summary
Given disjoint 2D mirror spheres and a ray, trace up to ten reflections and report which spheres the ray hits.
Level

Medium6 of 10

Topics
Geometry, Simulation, Implementation, Math
Solved
No attempts yet

Problem

Rendering realistic images of imaginary environments or objects is an interesting topic in computer graphics. One of the most popular methods for this purpose is ray tracing.

To render images using ray tracing, one traces the path that rays of light entering a scene take. In this problem you will write a program that computes such paths in a restricted environment.

For simplicity, we consider only two-dimensional scenes. Every object in the scene is a totally reflective (mirror) sphere. When a ray of light hits such a sphere, it is reflected so that the angle between the incoming ray and the tangent equals the angle between the leaving ray and the tangent.

Given a scene description and a ray entering the scene, your task is to determine which spheres the ray hits.

Input

The input consists of a series of scene descriptions. Each description starts with a line containing the number nn (n≤25n \le 25) of spheres in the scene. Each of the following nn lines contains three integers xix_i yiy_i rir_i, where (xi,yi)(x_i, y_i) is the center and ri>0r_i > 0 is the radius of the ii-th sphere. This is followed by a line containing four integers xx yy dxdx dydy describing the ray: it originates from the point (x,y)(x, y) and initially points in the direction (dx,dy)(dx, dy). At least one of dxdx and dydy is non-zero.

The spheres are disjoint and non-touching. The ray does not start inside a sphere and never touches a sphere tangentially.

A scene starting with n=0n = 0 terminates the input and must not be processed.

Output

For each scene, first output the scene number. Then print the numbers of the spheres that the ray hits within its first ten deflections (spheres are numbered according to their order in the input).

If the ray hits at most ten spheres and then heads towards infinity, print inf after the last sphere it hits. If the ray hits more than ten spheres, print three dots (...) after the tenth sphere.

Print a blank line between consecutive scenes.

Examples1

  1. Example 1

    Input
    3
    3 3 2
    7 7 1
    8 1 1
    3 8 1 -4
    2
    0 0 1
    5 0 2
    2 0 1 0
    0
    
    Expected output
    Scene 1
    1 2 1 3 inf
    
    Scene 2
    2 1 2 1 2 1 2 1 2 1 ...