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中的ArrayList类和LinkedList

    集合的体系: ----------| Collection 单列集合的根接口----------------| List 如果实现了List接口的集合类,具备的特点: 有序,可重复.--------- ...

  2. Java面向对象基础 ——面试题

    1面向对象基础 JAVA基础语法自行掌握. 三大特性: 一 封装:★★★★★ 概念:是指隐藏对象的属性和实现细节,仅对外提供公共访问方式. 好处:将变化隔离:便于使用:提高重用性:安全性. 封装原则: ...

  3. cocos2d-x的基本动作2

    1.基本动作 Cocos2d提供的基本动作:瞬时动作.延时动作.运作速度. 瞬时动作:就是不需要时间,马上就完成的动作.瞬时动作的共同基类是 InstantAction. Cocos2d提供以下瞬时动 ...

  4. Core BlueTooth官方文档翻译

    本⽂文是苹果<Core Bluetooth Programming Guide>的翻译. 关于Core Bluetooth Core Bluetooth 框架提供了蓝⽛牙低功耗⽆无线设备与 ...

  5. win8/10 bcdboot引导修复命令的原理和使用方法

    win8/10 bcdboot引导修复命令的原理和使用方法 [迅维网原创文章禁止转载] (本文所述已用UEFI+GPT.BIOS+MBR,WIN10 64位企业版和专业版测试过) 在win8/10系统 ...

  6. php过滤html标签

    <?php function kill_html($str){ //清除HTML标签 $st=-1; //开始 $et=-1; //结束 $stmp=array(); $stmp[]=" ...

  7. python3 连接 mysql和mariadb的模块

    是pymysql python2中是MySQL-python sudo pip install pymysql 参考博客https://www.jb51.net/article/140387.htm

  8. selenium2中的TestNg注解和数据驱动的简介及使用

    TestNg常用注解介绍,先来张图: 先看一下,以上各个注释的运行次序: @Test 表示的意义:    1.表示示该方法是一个测试方法,在运行时,会自动的运行有@Test注脚的方法. 示例: @Be ...

  9. POJ 3057 网络流 Evacuation

    题意: 有一个n×m的房间,四周每个格子要么是墙要么是门.中间部分是墙或者人. 现在所有人要从房间逃出去,每个人的速度为1,也就是每个单位时间只能向上下左右四个方向走一格. 多个人可以站在同一个格子上 ...

  10. JBuilder生成Exe

    首先保证工程可以通过绿箭头执行 然后在File菜单中选择New,先建立Archive下的Application 接下来的界面中大部分可以直接选择“Next”,除了下面的第3步,会询问是否需要将工程引用 ...