The projection of the HDU 2857 point on a straight line + the intersection of a straight line

Source: Internet
Author: User
Tags acos x2 y2
Mirror and light

Time Limit: 2000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 814 accepted submission (s): 385


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 input10.000 0.0004.000 0.0001.000 1.0003.000 1.000

 

Sample output2.0000.000

 

Source2009 multi-university training contest 5-host by nudt

 

Give a mirror (always-wire) to the point where the incident light passes and the point where the reflected light passes.

Idea: Find a point of symmetry about the mirror, and the intersection with the mirror is the incident point.

1 # include <iostream> 2 # include <cstdio> 3 # include <cstring> 4 # include <cmath> 5 using namespace STD; 6 7 const double EPS = 1e-10; 8 const double Pi = ACOs (-1.0); 9 struct point10 {11 double X, Y; 12 point (double x = 0, Double Y = 0): x (x ), Y (y) {}13}; 14 typedef point vector; 15 vector operator + (vector A, vector B) {return vector (. X + B. x,. Y + B. y);} 16 vector operator-(vector A, vector B) {return vector (. x-B.x ,. Y-B.y);} 17 vector operator * (vector A, Double P) {return vector (. x * P,. y * P);} 18 int DCMP (Double X) 19 {20 if (FABS (x) <EPS) return 0; 21 else return x <0? -1:1; 22} 23 24 double dot (vector A, vector B) {return. x * B. X +. y * B. y;} // dot product 25 double length (vector A) {return SQRT (dot (A, A);} // vector length 26 double angle (vector, vector B) {return ACOs (dot (A, B)/length (a)/length (B);} // The angle between the two vectors 27 double cross (vector, vector B) {return. x * B. y-A.y * B. x;} // Cross Product 28 point getlineprojection (point P, point A, point B) // P projection point 29 {30 vector v = B-A on the line AB; 31 return a + V * (dot (v, P-A)/DOT (V, V); 32} 33 point getlineintersection (point P, vector V, point Q, vector W) // intersection of two straight lines 34 {35 vector u = P-Q; 36 double T = cross (W, u)/Cross (V, W); 37 return P + V * t; 38} 39 40 point read_point () 41 {42 point P; 43 scanf ("% lf", & P. x, & P. y); 44 return P; 45} 46 int main () 47 {48 int t; 49 point P1, P2, P3, P4, P5; 50 scanf ("% d ", & T); 51 while (t --) 52 {53 p1 = read_point (); P2 = read_point (); P3 = read_point (); P4 = read_point (); 54 P5 = getlineprojection (P3, P1, P2); 55 P5 = P3 + (p5-p3) * 2; 56 P5 = getlineintersection (P5, p5-p4, P1, P2-P1 ); 57 printf ("%. 3lf %. 3lf \ n ", p5.x, p5.y); 58} 59 return 0; 60}

 

The projection of the HDU 2857 point on a straight line + the intersection of a straight line

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.