码迷,mamicode.com
首页 > 其他好文 > 详细

HDU 2857 Mirror and Light

时间:2017-03-08 21:33:39      阅读:204      评论:0      收藏:0      [点我收藏+]

标签:ace   bsp   span   name   extent   logs   lin   algorithm   stdin   

/* 
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

标签:ace   bsp   span   name   extent   logs   lin   algorithm   stdin   

原文地址:http://www.cnblogs.com/BBBob/p/6522916.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!