HDU 2857 Mirror and Light

Posted BBBob

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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的主要内容,如果未能解决你的问题,请参考以下文章

HDU 4276 The Ghost Blows Light(树形)

Turn Off The Light HDU - 6307

HDU-3698.Let the light guide us线段树优化DP

将 Solid and Light Font Awesome Pro 添加到 React 站点

LED Decorative Light Manufacturer - Decorative Lighting: Functionality And Aesthetics

19 Cameras, Lenses and Light Fields