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 course,it 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