Problem Description
The 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.
 
Input
The 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
1
0.000 0.000
4.000 0.000
1.000 1.000
3.000 1.000
 
Sample Output
2.000 0.000
 

思路:先求一个点关于镜子的对称点。再求该点与令一点确定的直线与镜子的交点。


#include <stdio.h>

void jd(double a1,double b1,double c1,double a2,double b2,double c2,double &x,double &y)//两直线交点
{
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)//两点确定的直线
{
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%lf%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x0,&y0,&x3,&y3); a1=x1-x2;//过(x0,y0)垂直与镜子的直线
b1=y1-y2;
c1=x0*x1-x0*x2+y0*y1-y0*y2; line(x1,y1,x2,y2,a2,b2,c2);//镜子所在直线 jd(a1,b1,c1,a2,b2,c2,x,y);//(x,y)上面两条直线的交点 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(计算几何)的更多相关文章

  1. HDU 2857 Mirror and Light

    /* hdu 2857 Mirror and Light 计算几何 镜面反射 */ #include<stdio.h> #include<string.h> #include& ...

  2. hdu 2857:Mirror and Light(计算几何,点关于直线的对称点,求两线段交点坐标)

    Mirror and Light Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  3. 「HDU - 2857」Mirror and Light(点关于直线的对称点)

    题目链接 Mirror and Light 题意 一条直线代表镜子,一个入射光线上的点,一个反射光线上的点,求反射点.(都在一个二维平面内) 题解 找出入射光线关于镜子直线的对称点,然后和反射光线连边 ...

  4. hdu 2857 点在直线上的投影+直线的交点

    Mirror and Light Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  5. hdu 2393:Higher Math(计算几何,水题)

    Higher Math Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  6. HDU 3698 Let the light guide us

    Let the light guide us Time Limit: 2000ms Memory Limit: 32768KB This problem will be judged on HDU. ...

  7. 题解 HDU 3698 Let the light guide us Dp + 线段树优化

    http://acm.hdu.edu.cn/showproblem.php?pid=3698 Let the light guide us Time Limit: 5000/2000 MS (Java ...

  8. HDU 5839 Special Tetrahedron (计算几何)

    Special Tetrahedron 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5839 Description Given n points ...

  9. hdu 3698 Let the light guide us(线段树优化&简单DP)

    Let the light guide us Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 62768/32768 K (Java/O ...

随机推荐

  1. C语言中字符串如何转换为二进制、八进制、十进制、十六进制

    在C语言某个程序当中需要把文本16进制转换成对应的16进制数,比如字符串"0x1a"转换成10进制的26,可以用以下函数来实现 相关函数: atof, atoi, atol, st ...

  2. android greenDao SQLite数据库操作使用的工具

    关于如何建立类生成一个演示project.今天介绍如何使用. 这是ExampleDaoGeneratorproject代码,做了一些改动 /* * Copyright (C) 2011 Markus ...

  3. AngularJS是为了克服HTML在构建应用上的不足而设计的

    AngularJS中文网:http://www.apjs.net/ 简介   AngularJS是为了克服HTML在构建应用上的不足而设计的.HTML是一门很好的为静态文本展示设计的声明式语言,但要构 ...

  4. poj1797(最短路小变形)

    题目连接:http://poj.org/problem?id=1797 题意: 分析:dp[i]表示到达i点的过程中的最大承受重量,更新到i点时可能有多条路径,由优先队列堆出最大的那条即可. #inc ...

  5. Urban Dictionary: psd

    Urban Dictionary: psd psd Share on twitter Share on facebook Share on more 3 up, 1 down It means Poo ...

  6. C++ Preprosessor import

    #import Attributes Provides links to attributes used with the #import directive. Microsoft Specific ...

  7. Mongodb数据备份恢复

    Mongodb数据备份恢复 一.MongoDB数据库导入导出操作 1.导出数据库 twangback为备份的文件夹 命令: mongodump -h 127.0.0.1[服务器IP] -d advie ...

  8. DataInputStream类readLong()引起的思考

    今天无意中看了下jdk中的DataInputStream类,然后看到readLong()方法,如下: private byte readBuffer[] = new byte[8]; public f ...

  9. mysql用户权限分配及主从同步复制

    赋予wgdp用户查询权限: grant select on wg_dp.* to 'wgdp'@'%' IDENTIFIED BY 'weigou123'; grant all privileges ...

  10. 计算机本科/硕士找offer的总结 节选

    在这样的目标定位下,我的求职历程从2006年10月8日开始,到2007年1月10日正式结束,一共持续了3个月的时间.整个过程可以分为三个阶段:第一阶段:2006年10月份 找工作刚刚开始的阶段,什么都 ...