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. Discount Diesel Time 9150-1 Quartz Wrist watch [WAT022]- US$4.49

    Discount Diesel Time 9150-1 Quartz Wrist watch [WAT022]- US$4.49 Diesel Time 9150-1 Quartz Wrist wat ...

  2. android中file的使用实例

    File是android的4种存储方式的一种.File就是文件的意思一个文件,你无非是想进行读写操作.所以这就用到两个流.一个数输入流,一个是输出流.FileOutstream,和FileInputS ...

  3. 读 Working with forms 一些心得

    Working with forms About this document This document provides an introduction to Django’s form handl ...

  4. android最近心得整理

    activity中OnAttachedWindow生命周期在OnResume之后,所以对长宽获取在推荐在OnAttachedWindow中进行. onDetachedWindow是在OnDestroy ...

  5. JSTL自定义标签库 (二)

    要定义自己的标签,首先写个java类,extends TagSupport  或者 implements Tag ,然后在类体里实现自己想要的方法,或者覆盖父类的方法. 我定义的MyTag代码如下: ...

  6. 程序猿进化 - 在拉钩子1024对APE节讲座计划

    注意:下面这篇文章来自于我在网上拉勾1024对APE节现场演示程序. 我是蒋宇捷,信天创投的合伙人.之前是百度魔图的联合创始人. 我先做个自我介绍,事实上每次介绍自己事实上是非常痛苦的事情,由于我前不 ...

  7. poj3176--Cow Bowling(dp:数塔问题)

    Cow Bowling Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 14028   Accepted: 9302 Desc ...

  8. Nagios+pnp4nagios+rrdtool 安装配置nagios(一)

    基于的软件版本 Apache-2.0.63  php-5.3.2 nagios-3.2.3  nagios-plugins-1.4.15  rrdtool-1.4.5 nrpe-2.12 pnp4na ...

  9. IOS开发应用

    IOS开发应用 我的第一个IOS开发应用 1. 需求描述 2. 开发环境介绍 3. 创建一个工程 4. 工程配置介绍 5. 目录结构介绍 6. 界面设置 7. 关联输入输出 8. 关联事件代码 9.  ...

  10. js创建下载文件

    function downloadFile(fileName, content){ var aLink = document.createElement('a'); var blob = new Bl ...