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. 第27本:《学得少却考得好Learn More Study Less》

    第27本:<学得少却考得好Learn More Study Less> <学得少却考得好Learn More Study Less>这本书最早是从褪墨网站上看到的,crownc ...

  2. NEU月赛Segment Balls(线段树)

    问题 D: Segment Balls 时间限制: 1 Sec  内存限制: 128 MB 提交: 253  解决: 37 题目描述 Small K has recently earn money i ...

  3. C#文件流写入方法

    stream为服务端接收的文件流 var bytes = new byte[stream.Length]; stream.Read(bytes, 0, bytes.Length); // 设置当前流的 ...

  4. linux crontab定时执行shell脚本

    linux下使用crontab命令被用来提交和管理用户的需要周期性执行的任务,示例如下:crontab -e 编辑周期任务30 21 * * * /etc/init.d/smb restart 每晚的 ...

  5. wampserver图标黄色

    wampserver图标黄色(多个httpd.exe服务,以前装了apache) 服务--->httpd.exe右击这个服务打开文件位置就知道是不是wampserver的服务.如果不是就停掉这给 ...

  6. ps、top 、free查看用户资源信息

      查看root用户的进程信息. 运行命令: ps -u root 查看oracle用户的进程信息. 运行命令: ps -u oracle 若查看现在的资源占用情况,如何呢? 运行命令: top 可以 ...

  7. HttpClient(联网)

    抽样: void GameRequest::initRequset(const char* url, cocos2d::CCObject* pTarget, cocos2d::SEL_CallFunc ...

  8. kafka解释三的具体:发展Kafka应用

    一个.整体外观Kafka 我们知道.Kafka系统有三大组件:Producer.Consumer.broker . producers 生产(produce)消息(message)并推(push)送给 ...

  9. 黄聪:Microsoft Enterprise Library 5.0 系列教程(四) Logging Application Block

    原文:黄聪:Microsoft Enterprise Library 5.0 系列教程(四) Logging Application Block 企业库日志应用程序模块工作原理图:   从上图我们可以 ...

  10. ActiveMQ相关背景(转)

    概述 介绍中间件.MOM.JMS.ActiveMQ,及相互的关系. 中间件 由于业务的不同.技术的发展.硬件和软件的选择有所差别,导致了异构组件或应用并存的局面.要使这些异构的组件协同工作,一个有效的 ...