Mirror and Light

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

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

题目大意:给一面镜子(一直线),给一入射光经过的点跟反射光经过的点,求入射点。

思路:求一个点关于镜子的对称点,与另一点与镜子的交点就是入射点。

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std; const double eps=1e-;
const double Pi=acos(-1.0);
struct Point
{
double x,y;
Point(double x=,double y=):x(x),y(y) {}
};
typedef Point Vector;
Vector operator +(Vector A,Vector B){return Vector(A.x+B.x,A.y+B.y);}
Vector operator -(Vector A,Vector B){return Vector(A.x-B.x,A.y-B.y);}
Vector operator *(Vector A,double p){return Vector(A.x*p,A.y*p);}
int dcmp(double x)
{
if(fabs(x)<eps) return ;
else return x<?-:;
} double Dot(Vector A,Vector B){return A.x*B.x+A.y*B.y;}//点积
double Length(Vector A){return sqrt(Dot(A,A));}//向量的长度
double Angle(Vector A,Vector B){return acos(Dot(A,B)/Length(A)/Length(B));}//两向量的夹角
double Cross(Vector A,Vector B){ return A.x*B.y-A.y*B.x;}//叉积
Point GetLineProjection(Point P,Point A,Point B)//P在直线AB上的投影点
{
Vector v=B-A;
return A+v*(Dot(v,P-A)/Dot(v,v));
}
Point GetLineIntersection(Point P,Vector v,Point Q,Vector w)//两直线的交点
{
Vector u=P-Q;
double t=Cross(w,u)/Cross(v,w);
return P+v*t;
} Point read_point()
{
Point p;
scanf("%lf%lf",&p.x,&p.y);
return p;
}
int main()
{
int t;
Point p1,p2,p3,p4,p5;
scanf("%d",&t);
while(t--)
{
p1=read_point();p2=read_point();p3=read_point();p4=read_point();
p5= GetLineProjection(p3,p1,p2);
p5=p3+(p5-p3)*;
p5=GetLineIntersection(p5,p5-p4,p1,p2-p1);
printf("%.3lf %.3lf\n",p5.x,p5.y);
}
return ;
}

hdu 2857 点在直线上的投影+直线的交点的更多相关文章

  1. BZOJ3403: [Usaco2009 Open]Cow Line 直线上的牛

    3403: [Usaco2009 Open]Cow Line 直线上的牛 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 48  Solved: 41[S ...

  2. BZOJ 3403: [Usaco2009 Open]Cow Line 直线上的牛( deque )

    直接用STL的的deque就好了... ---------------------------------------------------------------------- #include& ...

  3. 3403: [Usaco2009 Open]Cow Line 直线上的牛

    3403: [Usaco2009 Open]Cow Line 直线上的牛 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 71  Solved: 62[S ...

  4. 【BZOJ】3403: [Usaco2009 Open]Cow Line 直线上的牛(模拟)

    http://www.lydsy.com/JudgeOnline/problem.php?id=3404 裸的双端队列.. #include <cstdio> #include <c ...

  5. B3403 [Usaco2009 Open]Cow Line 直线上的牛 deque

    deque真的秀,queue和stack...没啥用了啊.操作差不多,就是在前面加一个front||back_就行了. 题干: 题目描述 题目描述     约翰的N只奶牛(编为1到N号)正在直线上排队 ...

  6. hdu 2857 求点关于线段的对称点

    本来很简单的一个题,但是有个大坑: 因为模板中Tline用到了直线的一般方程ax+by+c=0,所以有种很坑的情况需要特判: 斜率不存在啊喂 老子坑了一下午2333 #include <math ...

  7. p点到(a,b)点两所在直线的垂点坐标及p点是否在(a,b)两点所在直线上

     /// <summary>         ///  p点到(a,b)点两所在直线的垂点坐标         /// </summary>         /// <p ...

  8. lintcode 中等题:Max Points on a Line 最多有多少个点在一条直线上

    题目 最多有多少个点在一条直线上 给出二维平面上的n个点,求最多有多少点在同一条直线上. 样例 给出4个点:(1, 2), (3, 6), (0, 0), (1, 3). 一条直线上的点最多有3个. ...

  9. 一条直线上N个线段所覆盖的总长度

    原文:http://blog.csdn.net/bxyill/article/details/8962832 问题描述: 现有一直线,从原点到无穷大. 这条直线上有N个线段.线段可能相交. 问,N个线 ...

随机推荐

  1. java基础—this关键字

    一.this关键字

  2. Eclipse:Win10中设置Courier New字体

    问题:在Eclipse中设置字体的时候,没有找到Courier New字体.系统为Win10. 解决:Eclipse使用的字体为系统字体.在系统字体中有一部分是隐藏的.Courier New已经在系统 ...

  3. 实现HTTP文件下载

    [原文:http://www.jb51.net/article/89958.htm] HTTP实现文件下载时,只要在服务器设置好相关响应头,并使用二进制传输文件数据即可,而客户端(浏览器)会根据响应头 ...

  4. A. Vitya in the Countryside

    A. Vitya in the Countryside time limit per test 1 second memory limit per test 256 megabytes input s ...

  5. october安装过程

    下载代码 composer create-project october/october myoctober 准备好数据库, create database october; 配置环境于安装 php ...

  6. laravel中redis各方法的使用

    在laravel中使用redis自带方法的时候会发现许多原生的方法都不存在了,laravel对其进行了重新的封装但是在文档中并没有找到相关的资料最后在 \vendor\predis\predis\sr ...

  7. python-数据类型总结 (面试常问)

    目录 数字类型总结 拷贝 浅拷贝 深拷贝 数字类型总结 一个值 多个值 整型/浮点型/字符串 列表/字典/元祖/集合 有序 无序 字符串/列表/元祖 字典/集合 可变 不可变 列表/字典/集合 整型/ ...

  8. LeetCode(219) Contains Duplicate II

    题目 Given an array of integers and an integer k, find out whether there are two distinct indices i an ...

  9. stm32L0系列学习(二)HAL-LL库等比较

  10. HDU 3486 Interviewe RMQ

    题意: 将\(n\)个数分成\(m\)段相邻区间,每段区间的长度为\(\left \lfloor \frac{n}{m} \right \rfloor\),从每段区间选一个最大值,要让所有的最大值之和 ...