首页 > 代码库 > HDU 2857 Mirror and Light
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; double y; }; struct Line { double a; double b; double c; }; Point get_point1(Line x,Line y) { return (Point){ (x.b*y.c-y.b*x.c)/(x.a*y.b-y.a*x.b) , (y.a*x.c-x.a*y.c)/(x.a*y.b-y.a*x.b) }; } Point extent1(Point a,Point b) { return (Point){2*b.x-a.x,2*b.y-a.y}; } Line get_line1(Point a,Point b) { return (Line){ a.y-b.y , b.x-a.x , a.y*(a.x-b.x)-a.x*(a.y-b.y) }; } Line get_line1(Point a,Line x) { return (Line){ -x.b , x.a , x.b*a.x-x.a*a.y }; } int main() { //freopen("1005.in","r",stdin); scanf("%d",&t); Point ans; Point s,e,tmp,m1,m2,news; Line a,b,c; while(t--) { scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&x1,&y11,&x2,&y2,&xs,&ys,&xe,&ye); m1.x=x1;m1.y=y11; m2.x=x2;m2.y=y2; s=(Point){xs,ys},e=(Point){xe,ye}; //get b=get_line1(m1,m2); a=get_line1(s,b); tmp=get_point1(a,b); news=extent1(s,tmp); c=get_line1(news,e); ans=get_point1(c,b); if(fabs(ans.x-0.000)<1e-6) ans.x=0.000; if(fabs(ans.y-0.000)<1e-6) ans.y=0.000; printf("%.3lf %.3lf\n",ans.x,ans.y); } return 0; }
HDU 2857 Mirror and Light
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。