S. 21. The motion of a billiard ball (i.e. a point mass with completely elastic collisions) is studied. The ball moves on a rectangular table with some polygons blocking its way. The ball starts from a given boundary point of the table with a given initial velocity and moves along a straight line until it touches a side or a vertex of a polygon. Upon collision with a side, the velocity component perpendicular to the side changes sign. Collisions with a vertex are considered as if the ball collided with both sides meeting at the vertex. The simulation ends when the ball hits a side of the table.
The input text file of the program contains the coordinates of the table and the polygons. The first line of the file determines the sides of the table, the second line contains the initial position and velocity of the ball, while every other line describes the integer coordinates of the polygons. The input file does not contain empty lines or other data. All coordinates are integers between -1000 and 1000.
Example: the sides of the table are lines x=-200, x=+100, y=-150, y=300, hence the first line of the input file is -200 100 -150 300 (integers separated by spaces). The initial position of the ball is (-200,0) with velocity vector (5,12), so the second line of the input file contains numbers -200 0 5 12.
The table contains a triangle with coordinates (-20,50), (0,-40) and (50,30), so one further line of the input file is -20 50 0 -40 50 30. The sides of polygons are formed by connecting subsequent vertices. The polygon is closed by connecting the last vertex with the first one.
The name of the input file is read from the standard input, so we start the program, for example, by typing S21 input.txt. Your program should graphically display the path of the ball and give the coordinates of the point where it first hits the boundary of the table.
The source code of your program (S21.pas, S21.cpp, and a short documentation S21.txt should be submitted.
Deadline expired on 15 December 2006.
Google Translation (Sorry, the solution is published in Hungarian only.)
A feladat megoldásához koordináta-geometriai összefüggések pontos programozásával lehetett eljutni.
Két mintamegoldást mutatunk be: az egyik Windows környezetben a házi használatra ingyenes Microsoft VC++ Express változatával készült, Kezes Balázs érsekújvári diák munkája (megoldas1.cpp) és C++ nyelven készült; a másik Gilián Zoltán székesfehérvári tanuló FreePascal programja (gilianzoltan.pas).