HDU-2857-Mirror and light (Computational ry)

Source: Internet
Author: User
Tags x2 y2
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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.