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

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

2009 Multi-University Training Contest 5 - Host by NUDT

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

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

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <cmath>
 5 using namespace std;
 6
 7 const double eps=1e-10;
 8 const double Pi=acos(-1.0);
 9 struct Point
10 {
11     double x,y;
12     Point(double x=0,double y=0):x(x),y(y) {}
13 };
14 typedef Point Vector;
15 Vector operator +(Vector A,Vector B){return Vector(A.x+B.x,A.y+B.y);}
16 Vector operator -(Vector A,Vector B){return Vector(A.x-B.x,A.y-B.y);}
17 Vector operator *(Vector A,double p){return Vector(A.x*p,A.y*p);}
18 int dcmp(double x)
19 {
20     if(fabs(x)<eps) return 0;
21     else return x<0?-1:1;
22 }
23
24 double Dot(Vector A,Vector B){return A.x*B.x+A.y*B.y;}//点积
25 double Length(Vector A){return sqrt(Dot(A,A));}//向量的长度
26 double Angle(Vector A,Vector B){return acos(Dot(A,B)/Length(A)/Length(B));}//两向量的夹角
27 double Cross(Vector A,Vector B){ return A.x*B.y-A.y*B.x;}//叉积
28 Point GetLineProjection(Point P,Point A,Point B)//P在直线AB上的投影点
29 {
30     Vector v=B-A;
31     return A+v*(Dot(v,P-A)/Dot(v,v));
32 }
33 Point GetLineIntersection(Point P,Vector v,Point Q,Vector w)//两直线的交点
34 {
35     Vector u=P-Q;
36     double t=Cross(w,u)/Cross(v,w);
37     return P+v*t;
38 }
39
40 Point read_point()
41 {
42     Point p;
43     scanf("%lf%lf",&p.x,&p.y);
44     return p;
45 }
46 int main()
47 {
48     int t;
49     Point p1,p2,p3,p4,p5;
50     scanf("%d",&t);
51     while(t--)
52     {
53         p1=read_point();p2=read_point();p3=read_point();p4=read_point();
54         p5= GetLineProjection(p3,p1,p2);
55         p5=p3+(p5-p3)*2;
56         p5=GetLineIntersection(p5,p5-p4,p1,p2-p1);
57         printf("%.3lf %.3lf\n",p5.x,p5.y);
58     }
59     return 0;
60 }
时间: 2024-10-11 10:04:41

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

已知直线上两点求直线的一般式方程

一般式方程在计算机领域的重要性 常用的直线方程有一般式 点斜式 截距式 斜截式 两点式等等.除了一般式方程,它们要么不能支持所有情况下的直线(比如跟坐标轴垂直或者平行),要么不能支持所有情况下的点(比如x坐标相等,或者y坐标相等).所以一般式方程在用计算机处理二维图形数据时特别有用. 已知直线上两点求直线的一般式方程 已知直线上的两点P1(X1,Y1) P2(X2,Y2), P1 P2两点不重合.则直线的一般式方程AX+BY+C=0中,A B C分别等于: A = Y2 - Y1 B = X1

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

3403: [Usaco2009 Open]Cow Line 直线上的牛 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 71  Solved: 62[Submit][Status] Description 题目描述 约翰的N只奶牛(编为1到N号)正在直线上排队.直线上开始的时候一只牛也没有.接下来发生了S(1≤S≤100000)次事件,一次事件可能是以下四种情况之一: .一只奶牛加入队伍的左边(输入“AL”). .一只奶牛加入队伍的右边(输入“AR

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

直接用STL的的deque就好了... ---------------------------------------------------------------------- #include<cstdio> #include<algorithm> #include<cstring> #include<iostream> #include<deque> #define rep( i , n ) for( int i = 0 ; i <

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

3403: [Usaco2009 Open]Cow Line 直线上的牛 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 48  Solved: 41[Submit][Status] Description 题目描述 约翰的N只奶牛(编为1到N号)正在直线上排队.直线上开始的时候一只牛也没有.接下来发生了S(1≤S≤100000)次事件,一次事件可能是以下四种情况之一: .一只奶牛加入队伍的左边(输入“AL”). .一只奶牛加入队伍的右边(输入“AR

HDU 2857 Mirror and Light

/* hdu 2857 Mirror and Light 计算几何 镜面反射 */ #include<stdio.h> #include<string.h> #include<math.h> #include<algorithm> using namespace std; const double DNF=100000001.0; int t; double x1,x2,y11,y2,xs,ys,xe,ye; struct Point { double x;

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

本来很简单的一个题,但是有个大坑: 因为模板中Tline用到了直线的一般方程ax+by+c=0,所以有种很坑的情况需要特判: 斜率不存在啊喂 老子坑了一下午2333 1 #include <math.h> 2 #include <stdio.h> 3 4 #define eps 1e-6 5 #define PI acos(-1.0)//3.14159265358979323846 6 //判断一个数是否为0,是则返回true,否则返回false 7 #define zero(x)

平面坐标系中,求点在线上的投影坐标(如图)

已知点A(x1,y1).B(x2,y2).M(m,n),求点M在线段AB上的投影坐标. .....

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

原文:http://blog.csdn.net/bxyill/article/details/8962832 问题描述: 现有一直线,从原点到无穷大. 这条直线上有N个线段.线段可能相交. 问,N个线段总共覆盖了多长?(重复覆盖的地区只计算一次) ================================================ 解题思路: 可以将每个线段拆分成“单位1” 遍历所有线段,使用一个数组记录每个线段所走过的“单位1” 最后统计数组中被走过的中“单位1”的个数,即是所有线

已知直线上的两点 A(x1, y1), B(x2, y2) 和另外一点 C(x0, y0),求C点到直线的距离。

数学知识太差,一点点积累,高手勿喷. 1. 先求出AB向量 a = ( x2-x1, y2-y1 ) 2. 求AB向量的单位方向向量 b = √((x2-x1)^2 + (y2-y1)^2)) a1 = ( (x2-x1)/b, (y2-y1)/b ) 3.求出CA的法向向量(或CB的法向向量) c = ( y0-y1, -(x0-x1) ) 4. 距离 = AC法向向量与BC向量的单位方向向量的数量积 距离d = a1 * c = ( (x2-x1)(y0-y1) - (y2-y1)(x0-x