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. sql存储过程等-版本控制

    数据库开发人员总在想,每次修改了函数/存储过程,我们都得自己做备份,用以历史参考,当发现错误的时候,可以回滚 SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON ...

  2. 如何自动生成Makefile

    作为Linux下的程序开发人员,大家一定都遇到过Makefile,用make命令来编译自己写的程序确实是很方便.一般情况下,大家都是手工写一个简单Makefile,如果要想写出一个符合自由软件惯例的M ...

  3. nginx根据token做频率限制

    在 nginx.conf 文件添加配置 limit_conn_log_level error; limit_conn_status ; limit_conn_zone $cookie_gray_DF_ ...

  4. checkbox显示选中内容个数

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  5. const与#define、结构体对齐、函数重载name mangling、new/delete 等

    一.bool 类型 逻辑型也称布尔型,其取值为true(逻辑真)和false(逻辑假),存储字节数在不同编译系统中可能有所不同,VC++中为1个字节. 声明方式:bool result; result ...

  6. django 错误信息

    一.No module named 'requests' 安装: pip install django-salmonella 二.No module named 'requests' 安装: pip ...

  7. AutoFac文档3(转载)

    目录 开始 Registering components 控制范围和生命周期 用模块结构化Autofac xml配置 与.net集成 深入理解Autofac 指导 关于 词汇表 服务类型,名称和键 同 ...

  8. spring session配置

    spring session是一个解决集群环境中,session持久化管理的依赖库.配置非常简单. 在spring boot环境中添加依赖 <dependency> <groupId ...

  9. Unity3D动画面板编辑器状态属性对照表

    不推荐用AnimationUtility.SetEditorCurve问题很多,推荐AnimationCurve.AddKey.通过AnimationUtility.GetAllCurves可以获得编 ...

  10. Storyboard 全解析

    XCode 4.3.2 新功能 - Storyboard 最近开始比较有空在玩 XCode 4.3.2,赫然发现它多了个 Storyboard 的东东. Storyboard 这个东西一般来说是在做创 ...