Mirror and light
Time Limit: 2000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 821 accepted submission (s): 387
Problem descriptionthe light travels in a straight line and always goes in the minimal path between two points, are the basic laws of optics.
Now, our problem is that, if a branch of light goes into a large and infinite mirror, of course, it will reflect, and leave away the mirror in another direction. giving you the position of mirror and the two points the light goes in before and after the reflection, calculate the reflection point of the light on the mirror.
You can assume the mirror is a straight line and the given two points can't be on the different sizes of the mirror.
Inputthe first line is the number of test case T (t <= 100 ).
The following every four lines are as follow:
X1 Y1
X2 Y2
Xs YS
Xe ye
(X1, Y1), (X2, Y2) mean the different points on the mirror, and (XS, ys) means the point the light travel in before the reflection, and (xe, ye) is the point the light go after the reflection.
The eight real number all are rounded to three digits after the decimal point, and the absolute values are no larger than 10000.0.
Output each lines have two real number, rounded to three digits after the decimal point, representing the position of the Reflection Point.
Sample Input
10.000 0.0004.000 0.0001.000 1.0003.000 1.000
Sample output
2.000 0.000
Source2009 multi-university training contest 5-host by nudt
Direct template set;
# Include <cstdio> # include <algorithm> # include <iostream> using namespace STD; struct point {Double X, Y; point (double x = 0, Double Y = 0 ): x (x), y (y) {}; void input () {scanf ("% lf", & X, & Y) ;}} point [5]; int main () {int t; scanf ("% d", & T); While (t --) {for (INT I = 0; I <4; I ++) point [I]. input (); double a1 = point [1]. y-point [0]. y; double b1 = point [0]. x-point [1]. x; double C1 = point [0]. y * point [1]. x-point [0]. x * point [1]. y; double A2, B2, C2; Double X, Y, K; k =-2.0*(A1 * point [2]. X + B1 * point [2]. Y + C1)/(A1 * A1 + B1 * B1); X = point [2]. X + K * A1; y = point [2]. Y + K * B1; a2 = point [3]. y-y; b2 = x-point [3]. x; C2 = y * point [3]. x-point [3]. y * X; double X1 = (C2 * B1-C1 * B2)/(A1 * B2-A2 * B1); double Y1 = (C1 * A2-C2 * A1) /(A1 * B2-A2 * B1); If (b1 = 0) x1 = point [0]. x; // you do not need to consider either of these two cases, because if (a1 = 0) Y1 = point [0]. y; printf ("%. 3lf %. 3lf \ n ", X1, Y1);} return 0 ;}
Mirror and light (points and straight lines)