HDU 2857 mirror and light

Source: Internet
Author: User

There is a mirror, and a bunch of light comes in. We know that the mirror coordinates (x1, Y1) (X2, Y2) are two points to determine the mirror surface, the incident point of light and the reflected point of light. Calculate the coordinates of the points on the mirror.

Idea: for example

(1) Straight Line (x1, Y1) (X2, Y2)

(2) obtain the symmetry points (TMP. X, TMP. Y) of a straight line (x1, Y1) (X2, Y2)

(3) evaluate a straight line (TMP. X, TMP. Y) (E. X, E. Y)

(4) Calculate the intersection of (x1, Y1) (X2, Y2) and (TMP. X, TMP. Y) (E. X, E. Y) (x, y)


Formula:

· If two points (x1, Y1) (X2, Y2) on a known straight line are known, the straight line AX + by + c = 0 is obtained.

A = y2-y1; B = x1-x2; C = Y1 * x2-x1 * Y2;


· Known (x0, y0), obtain the symmetric point (x, y) about the straight line AX + by + c = 0)

K =-2 * (A * x0 + B * y0 + C)/(A * A + B * B );

X = x0 + K *;

Y = y0 + K * B;


· Intersection of known straight lines and straight lines (x, y)

If b1 = 0

Otherwise

AC code

# Include <iostream> # include <cstdio> using namespace STD; struct node {Double X, Y ;}; double A1, B1, C1, A2, B2, C2, K; node N1, N2, S, E, node1; int main () {int N; CIN> N; while (n --) {scanf ("% lf", & n1.x, & n1.y, & n2.x, & n2.y, & S. x, & S. y, & E. x, & E. y); {// locate the mirror line a1 = n2.y-n1.y; b1 = n1.x-n2.x; C1 = n1.y * n2.x-n1.x * n2.y; // obtain the symmetry point K =-2*(A1 * s. X + B1 * s. Y + C1)/(A1 * A1 + B1 * B1); node1.x = S. X + K * A1; node1.y = S. Y + K * B1; a2 = E. y-node1.y; b2 = node1.x-e. x; C2 = node1.y * E. x-node1.x * E. y; // calculate the intersection of two straight lines Double X, Y; If (b1 = 0) {x =-C1/A1; y = (-c2-a2 * X) /B2;} else {x = (C2 * b1-c1 * B2)/(A1 * b2-a2 * B1); y = (-A1 * x-c1)/B1 ;} printf ("%. 3lf %. 3lf \ n ", x, y) ;}} return 0 ;}

Zookeeper

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.