Mirror and Light

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 650    Accepted Submission(s): 316

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
 
Source
 
Recommend
gaojie   |   We have carefully selected several similar problems for you:  2855 2856 2854 2860 2861 

 
  计算几何:求点关于直线的对称点 + 两线段交点
  直接copy了别人的模板,写的有些混乱,见谅!有时间再研究。
  参考链接:
  代码:
 #include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
struct Point {double x,y;}; //点
struct Ldir{double dx,dy;}; //方向向量
struct Lline{Point p; Ldir dir;}; //直线
// 计算直线的一般式 Ax+By+C=0
void format(Lline ln,double& A,double& B,double& C)
{
A=ln.dir.dy;
B=-ln.dir.dx;
C=ln.p.y*ln.dir.dx-ln.p.x*ln.dir.dy;
}
// 求点p1关于直线ln的对称点p2
Point mirror(Point P,Lline ln)
{
Point Q;
double A,B,C;
format(ln,A,B,C);
Q.x=((B*B-A*A)*P.x-*A*B*P.y-*A*C)/(A*A+B*B);
Q.y=((A*A-B*B)*P.y-*A*B*P.x-*B*C)/(A*A+B*B);
return Q;
}
//求线段交点
struct TLine
{
//直线标准式中的系数
double a, b, c;
};
TLine lineFromSegment(Point p1, Point p2)
{
TLine tmp;
tmp.a = p2.y - p1.y;
tmp.b = p1.x - p2.x;
tmp.c = p2.x * p1.y - p1.x * p2.y;
return tmp;
}
/*求直线的交点,注意平形的情况无解,避免RE*/
const double eps = 1e-; //注意一定要加,否则错误
Point LineInter(TLine l1, TLine l2)
{
//求两直线得交点坐标
Point tmp;
double a1 = l1.a;
double b1 = l1.b;
double c1 = l1.c;
double a2 = l2.a;
double b2 = l2.b;
double c2 = l2.c;
//注意这里b1 = 0
if(fabs(b1) < eps){
tmp.x = -c1 / a1;
tmp.y = (-c2 - a2 * tmp.x) / b2;
}
else{
tmp.x = (c1 * b2 - b1 * c2) / (b1 * a2 - b2 * a1);
tmp.y = (-c1 - a1 * tmp.x) / b1;
}
return tmp;
}
int main()
{
int T;
cin>>T;
cout<<setiosflags(ios::fixed)<<setprecision();
while(T--){
Point p1,p2,ps,pe;
Lline l;
cin>>p1.x>>p1.y;
cin>>p2.x>>p2.y;
cin>>ps.x>>ps.y;
cin>>pe.x>>pe.y;
l.p = p1;
l.dir.dx = p2.x - p1.x;
l.dir.dy = p2.y - p1.y;
Point duichen = mirror(ps,l); //求对称点
//cout<<duichen.x<<' '<<duichen.y<<endl;
TLine l1,l2;
l1 = lineFromSegment(p1,p2);
l2 = lineFromSegment(duichen,pe);
Point inter = LineInter(l1,l2); //求交点
cout<<inter.x<<' '<<inter.y<<endl;
}
return ;
}

Freecode : www.cnblogs.com/yym2013

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 题意 一条直线代表镜子,一个入射光线上的点,一个反射光线上的点,求反射点.(都在一个二维平面内) 题解 找出入射光线关于镜子直线的对称点,然后和反射光线连边 ...

  3. Gym-101915B Ali and Wi-Fi 计算几何 求两圆交点

    题面 题意:给你n个圆,每个圆有一个权值,你可以选择一个点,可以获得覆盖这个点的圆中,权值最大的m个的权值,问最多权值是多少 题解:好像是叙利亚的题....我们画画图就知道,我们要找的就是圆与圆交的那 ...

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

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

  5. hdu 1086:You can Solve a Geometry Problem too(计算几何,判断两线段相交,水题)

    You can Solve a Geometry Problem too Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/3 ...

  6. sgu 129 Inheritance 凸包,线段交点,计算几何 难度:2

    129. Inheritance time limit per test: 0.25 sec. memory limit per test: 4096 KB The old King decided ...

  7. hdu 1147:Pick-up sticks(基本题,判断两线段相交)

    Pick-up sticks Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

  8. HDU 1171 Big Event in HDU【01背包/求两堆数分别求和以后的差最小】

    Big Event in HDU Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...

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

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

随机推荐

  1. Linux下统计当前文件夹下的文件个数、目录个数(转)

    1) 统计当前文件夹下文件的个数 代码如下: ls -l |grep "^-"|wc -l 2) 统计当前文件夹下目录的个数 代码如下: ls -l |grep "^d& ...

  2. jquery uploadify文件上传插件用法精析

      jquery uploadify文件上传插件用法精析 CreationTime--2018年8月2日11点12分 Author:Marydon 一.参数说明 1.参数设置 $("#fil ...

  3. nginx代理tomcat

    http://blog.csdn.net/kongqz/article/details/6838989 http://www.800l.com/linux-nginx-tomcat-jdk.html ...

  4. 在eclipse中将android工程打包生成apk文件

    1.)生成keystore 按照下面的命令行 在C:\Program Files\Java\jdk1.6.0_10\bin>目录下,输入keytool -genkey -alias androi ...

  5. 建立对ActiveX控件的了解

    本文来自百度百科:ActiveX控件   ActiveX是Microsoft对于一系列策略性面向对象程序技术和工具的称呼,其中主要的技术是组件对象模型(COM).在有目录和其它支持的网络中,COM变成 ...

  6. 树莓派/RaspberryPi Ubuntu远程连接

    网络设置 设置Ubuntu主机跟树莓派在同一网段,树莓派设置静态IP地址: 查看/etc/network/interfaces的内容,其中有#For static IP, consult /etc/d ...

  7. C#指南,重温基础,展望远方!(8)C#数组

    数组是一种数据结构,其中包含许多通过计算索引访问的变量. 数组中的变量(亦称为数组的元素)均为同一种类型,我们将这种类型称为数组的元素类型. 数组类型是引用类型,声明数组变量只是为引用数组实例预留空间 ...

  8. Phonegap创建项目语法

    1:在本地磁盘新建一个文件夹存放要开发的项目,比如在D盘建一个yun文件夹2 2:然后在dos系统下,d:命令进入d盘,cd yun进入yun文件夹, 3:然后phonegap create yun2 ...

  9. (2)FluidMoveBehavior 之单击 Grid 中 Tile 进行排序

    在上一篇文章中,使用 FluidMoveBehavior 结合 FluidMoveSetTagBehavior 可以使数据从 ListBox 中的 数据显示时,产生缓慢的动画,从而更加生动.其实 Fl ...

  10. spring boot文件上传、下载

    主题:Spring boot 文件上传(多文件上传)[从零开始学Spring Boot]http://www.iteye.com/topic/1143595 Spring MVC实现文件下载http: ...