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. 1
  2. 0.000 0.000
  3. 4.000 0.000
  4. 1.000 1.000
  5. 3.000 1.000
 
Sample Output
  1. 2.000 0.000
 

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


  1. #include <stdio.h>
  2.  
  3. void jd(double a1,double b1,double c1,double a2,double b2,double c2,double &x,double &y)//两直线交点
  4. {
  5. x=(b2*c1-b1*c2)/(a1*b2-a2*b1);
  6. y=(a2*c1-a1*c2)/(a2*b1-a1*b2);
  7. }
  8.  
  9. void line(double x1,double y1,double x2,double y2,double &a,double &b,double &c)//两点确定的直线
  10. {
  11. a=y1-y2;
  12. b=x2-x1;
  13. c=x2*y1-x1*y2;
  14. }
  15.  
  16. int main()
  17. {
  18. int T;
  19. double x1,x2,y1,y2,x0,y0,x3,y3,a1,a2,b1,b2,c1,c2,x,y;
  20.  
  21. scanf("%d",&T);
  22.  
  23. while(T--)
  24. {
  25. scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x0,&y0,&x3,&y3);
  26.  
  27. a1=x1-x2;//过(x0,y0)垂直与镜子的直线
  28. b1=y1-y2;
  29. c1=x0*x1-x0*x2+y0*y1-y0*y2;
  30.  
  31. line(x1,y1,x2,y2,a2,b2,c2);//镜子所在直线
  32.  
  33. jd(a1,b1,c1,a2,b2,c2,x,y);//(x,y)上面两条直线的交点
  34.  
  35. x+=x-x0;
  36. y+=y-y0;
  37.  
  38. line(x,y,x3,y3,a1,b1,c1);
  39.  
  40. jd(a1,b1,c1,a2,b2,c2,x,y);
  41.  
  42. printf("%.3f %.3f\n",x,y);
  43. }
  44. }

版权声明:本文博主原创文章。博客,未经同意不得转载。

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. _tcscat在Debug和Release根据问题

    背景: 因此,例如,在下面的代码段,作用是得到的路径当前程序(C:\work\A.exe),然后"A.exe"拆除,组装的"C:\work\inject.dll" ...

  2. Nagios监控系统的安装

    环境:centOS 6.5 X86 64位 nagios-4.08 步骤: 1.  最小化安装系统 2.  修改安全特性 关闭SELINUX     SELINUX=disabled 清除iptabl ...

  3. Merging a WPF application into a single EXE(WPF应用程序合并成单个Exe文件)

    I always dislike handing off little applications to people. Not because I can’t, but because of the ...

  4. Net Kafka

    Net Kafka Kafka 协议实现中的内存优化 Jusfr 2016-04-18 08:28 阅读:241 评论:1     Kafka API: TopicMetadata Jusfr 201 ...

  5. MongoDB--Getting Started with Java Driver

    原文链接 http://docs.mongodb.org/ecosystem/tutorial/getting-started-with-java-driver/  介绍 本文的目的是让你对怎样使用M ...

  6. [cocos2dx-lua]&quot;Hello Lua&quot;分析

    一年之前学的cocos2dx,那时候还是用C++编写的.但学完之后就找的一个新的方向--Unity3D开发的岗位,对我而言是一个新方向,那时候经过了几个月的每天熬夜奋战,从"0"基 ...

  7. c语言推断数是否是素数

    这是推断数是否是素数.网络版非常.我觉得有点问题.今天一个朋友问我这个问题.我知道,今天,我把自己的代码,非常实用哦!. #include<stdio.h> #include<mat ...

  8. java名词,关键字

    抽象类:规定一个或多个抽象方法的类别本身必须定义为abstract,抽象类只是用来派生子类,而不能用它来创建对象. final类:又称“最终类”,它只能用来创建对象,而不能被继承,与抽象类刚好相反,而 ...

  9. Hibernate4 : 持久化你的第一个类

    由于目前我在学校的一个实验室跟老师学习Java EE开发,老师用的是Seam框架接活做项目,所以这一系列的文章将会向Seam方向写..路线大致应该是 : JSP --> Servlet --&g ...

  10. windows phone 了解LinearGradientBrush类和RadialGradienBrush类(11)

    原文:windows phone 了解LinearGradientBrush类和RadialGradienBrush类(11) 我们了解到在能在xaml中完成的设计,一般在隐藏文件中也可通过代码完成: ...