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
Idea: first find a point of symmetry about the mirror, and then find the point of intersection between the point and the determined line and the mirror.
# Include <stdio. h> void JD (double A1, double B1, double C1, double A2, double B2, double C2, double & X, double & Y) // two straight line intersection {x = (B2 * c1-b1 * C2)/(A1 * b2-a2 * B1); y = (A2 * C1-A1 * C2) /(A2 * b1-a1 * B2);} void line (double X1, double Y1, double X2, double Y2, double & A, double & B, double & C) // two points determine the straight line {A = y1-y2; B = x2-x1; C = x2 * y1-x1 * Y2;} int main () {int t; double x1, x2, Y1, y2, x0, y0, X3, Y3, A1, A2, B1, B2, C1, C2, X, Y; scanf ("% d", & T ); while (t --) {scanf ("% lf", & X1, & Y1, & X2, & Y2, & x0, & y0, & X3, & Y3); a1 = x1-x2; // (x0, y0) vertical line b1 = y1-y2 with mirror; c1 = x0 * x1-x0 * X2 + y0 * y1-y0 * Y2; line (x1, Y1, X2, Y2, A2, B2, C2); // mirror line JD (A1, b1, C1, A2, B2, C2, x, y); // (x, y) the intersection of the above two straight lines X + = x-x0; y + = y-y0; line (X, Y, X3, Y3, A1, B1, C1); JD (A1, B1, C1, A2, B2, C2, x, y ); printf ("%. 3f %. 3f \ n ", x, y );}}
HDU-2857-Mirror and light (Computational ry)