HDU-2857-Mirror and Light(计算几何)
2015-10-05 18:37
435 查看
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
Sample Output
思路:先求一个点关于镜子的对称点。再求该点与令一点确定的直线与镜子的交点。
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
思路:先求一个点关于镜子的对称点。再求该点与令一点确定的直线与镜子的交点。
#include <stdio.h> void jd(double a1,double b1,double c1,double a2,double b2,double c2,double &x,double &y)//两直线交点 { x=(b2*c1-b1*c2)/(a1*b2-a2*b1); y=(a2*c1-a1*c2)/(a2*b1-a1*b2); } void line(double x1,double y1,double x2,double y2,double &a,double &b,double &c)//两点确定的直线 { a=y1-y2; b=x2-x1; c=x2*y1-x1*y2; } int main() { int T; double x1,x2,y1,y2,x0,y0,x3,y3,a1,a2,b1,b2,c1,c2,x,y; scanf("%d",&T); while(T--) { scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x0,&y0,&x3,&y3); a1=x1-x2;//过(x0,y0)垂直与镜子的直线 b1=y1-y2; c1=x0*x1-x0*x2+y0*y1-y0*y2; line(x1,y1,x2,y2,a2,b2,c2);//镜子所在直线 jd(a1,b1,c1,a2,b2,c2,x,y);//(x,y)上面两条直线的交点 x+=x-x0; y+=y-y0; line(x,y,x3,y3,a1,b1,c1); jd(a1,b1,c1,a2,b2,c2,x,y); printf("%.3f %.3f\n",x,y); } }
相关文章推荐
- 名字与地址转换getservbyname 与 getservbyport函数
- 归并排序-java
- kafka分布式消息系统
- kafka java示例
- 【codevs1154】 能量项链
- 表单重复提交处理
- ipvsadm命令参考
- ipvsadm --persistent 与 --set
- php get_magic_quotes_gpc()函数
- unity3D 4.6与上述号码. UI穿透问题,而且不穿透的真机模拟器渗透问题解决
- 如何修改内核启动的logo
- Longest Substring Without Repeating Characters
- 面试问题准备
- http状态码
- 空气净化器的过滤网能够清洗吗?怎样清洗?
- Java多线程16:线程组
- http转义字符
- http content type
- hive操作base
- 计算