HDU-2857-Mirror and Light(计算几何)

Problem Description

The light travels in a straight line and always goes in the minimal path between two points, are the basic laws of optics.

Now, our problem is that, if a branch of light goes into a large and infinite mirror, of course,it will reflect, and leave away the mirror in another direction. Giving you the position of mirror and the two points the light goes in before and after the reflection,
calculate the reflection point of the light on the mirror.

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

Input

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

The following every four lines are as follow:

X1 Y1

X2 Y2

Xs Ys

Xe Ye

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

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

Output

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

思路:先求一个点关于镜子的对称点,再求该点与令一点确定的直线与镜子的交点。

#include <stdio.h>

void jd(double a1,double b1,double c1,double a2,double b2,double c2,double &x,double &y)//两直线交点
{
    x=(b2*c1-b1*c2)/(a1*b2-a2*b1);
    y=(a2*c1-a1*c2)/(a2*b1-a1*b2);
}

void line(double x1,double y1,double x2,double y2,double &a,double &b,double &c)//两点确定的直线
{
    a=y1-y2;
    b=x2-x1;
    c=x2*y1-x1*y2;
}

int main()
{
    int T;
    double x1,x2,y1,y2,x0,y0,x3,y3,a1,a2,b1,b2,c1,c2,x,y;

    scanf("%d",&T);

    while(T--)
    {
        scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x0,&y0,&x3,&y3);

        a1=x1-x2;//过(x0,y0)垂直与镜子的直线
        b1=y1-y2;
        c1=x0*x1-x0*x2+y0*y1-y0*y2;

        line(x1,y1,x2,y2,a2,b2,c2);//镜子所在直线

        jd(a1,b1,c1,a2,b2,c2,x,y);//(x,y)上面两条直线的交点

        x+=x-x0;
        y+=y-y0;

        line(x,y,x3,y3,a1,b1,c1);

        jd(a1,b1,c1,a2,b2,c2,x,y);

        printf("%.3f %.3f\n",x,y);
    }
}
时间: 2024-08-25 00:20:10

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;

HDOJ 题目2857 Mirror and Light(关于直线对称点,直线交点)

Mirror and Light Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Submission(s) : 1   Accepted Submission(s) : 1 Problem Description The light travels in a straight line and always goes in the minimal path betwee

HDU 3272 - Mission Impossible(计算几何)

HDU 3272 - Mission Impossible(计算几何) ACM 题目地址: HDU 3272 - Mission Impossible 题意: 在二维平面上,给你一个初始位置(hx,hy),你需要获得四种资源,A在x轴上任意位置,B在y轴上任意位置,C.D位置会告诉你.问获得四种资源后返回(hx,hy)最短要走多长. 分析: 三条线段与X.Y轴相交有三种情况: 与x,y都相交,此时最短距离为周长 仅与X或Y相交,这时枚举每条边,利用镜像对称算出距离,取最小值 与X和Y都不相交,这

hdu 2857 点在直线上的投影+直线的交点

Mirror and Light Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 814    Accepted Submission(s): 385 Problem Description The light travels in a straight line and always goes in the minimal path b

题解 HDU 3698 Let the light guide us Dp + 线段树优化

http://acm.hdu.edu.cn/showproblem.php?pid=3698 Let the light guide us Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 62768/32768 K (Java/Others) Total Submission(s): 759    Accepted Submission(s): 253 Problem Description Plain of despair was

Mirror and Light (点与直线)

Mirror and Light Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 821    Accepted Submission(s): 387 Problem Description The light travels in a straight line and always goes in the minimal path

【HDU 1687】Lucky Light(思维+计算几何)

传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1687 题意:有一个光源,下面有很多放置的板子,问光线被板子分割之后在地上能产生多少块亮区(看题中的图就能看懂). 分析:这个题的做法和省选第一天的C题很像,由于是求在地面上,也就是一条直线上的亮区,我们可以求出地面上被木板遮挡形成的暗区的左坐标和右坐标,然后合并区间就可以了.而求地面上的坐标,可以用相似三角形,若光源为(sx,sy),点为(x1,y1)和(x2,y2),则地面上的坐标为:sx-(sx-

HDU 3698 Let the light guide us

Let the light guide us Time Limit: 2000ms Memory Limit: 32768KB This problem will be judged on HDU. Original ID: 369864-bit integer IO format: %I64d      Java class name: Main Plain of despair was once an ancient battlefield where those brave spirits

hdu 2393:Higher Math(计算几何,水题)

Higher Math Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2219    Accepted Submission(s): 1219 Problem Description You are building a house. You'd prefer if all the walls have a precise right