hdu2857 2010.3.6

hdu2857 2010.3.6

hdu 2857

镜面反射


#include <stdio.h>
#include <math.h>

	int t,i;
	double x1,x2,y1,y2,xs,ys,xe,ye;
	double a,b,x,y,s;
	double l1,l2;
	double px1,px2,py1,py2;	

void main()
{
	scanf("%d",&t);
	for(i=1;i<=t;i++)
	{
		scanf("%lf %lf %lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&xs,&ys,&xe,&ye);
		if (x1==x2)
		{
			s=fabs(xs-x1)/fabs(xe-x1);
			y=(ys+s*ye)/(1+s);
			x=x1;
		}
		else
			if (y1==y2)
			{
				s=fabs(ys-y1)/fabs(ye-y1);
				x=(xs+s*xe)/(1+s);
				y=y1;
			}
			else
			{
				a=(y1-y2)/(x1-x2);
				b=y1-a*x1;
				l1=fabs(a*xs-ys+b)/sqrt(a*a+1);
				l2=fabs(a*xe-ye+b)/sqrt(a*a+1);
				s=l1/l2;
				px1=(ys+1/a*xs-b)*a/(a*a+1);
				px2=(ye+1/a*xe-b)*a/(a*a+1);
				py1=a*px1+b;
				py2=a*px2+b;
				x=(px1+s*px2)/(1+s);
				y=(py1+s*py2)/(1+s);
			}
		printf("%.3lf %.3lf\n",x,y);
	}
}

Mirror and Light

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 175    Accepted Submission(s): 114

 

 

Problem Description

The light travels in a straight line andalways goes in the minimal path between two points, are the basic laws ofoptics.

 

Now, our problem is that, if a branch oflight goes into a large and infinite mirror, of courseit willreflect, and leave away the mirror in another direction. Giving you theposition of mirror and the two points the light goes in before and after thereflection, calculate the reflection point of the light on the mirror.

 

You can assume the mirror is a straightline and the given two points can’t be on the different sizes of the mirror.

 

 

Input

The first line is the number of test caset(t<=100).

 

The following every four lines are asfollow:

  X1Y1

  X2Y2

  XsYs

  XeYe

 

 (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 thepoint the light go after the reflection.

 

  Theeight real number all are rounded to three digits after the decimal point, andthe absolute values are no larger than 10000.0.

 

 

Output

 Each lines have two real number, rounded to three digits after thedecimal 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

 

 

Recommend

gaojie

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值