HDU 2857 Mirror and Light(형상)

1869 단어 ror
제목 링크
간단하게 반사점을...이런 기하 문제를 순서로 쓰면 어떻게 이렇게 쉽게 틀리지?4Y...중간에 각종 작은 실수.
#include <stdio.h>

#include <string.h>

#define eps 0.00000001

double xmi,ymi,xx,yy;

void line(double x1,double y1,double x2,double y2,double xs,double ys)// (xs,ys)        

{

    double k1,k2,b1,b2;

    if(y2 == y1)

    {

        xmi = xs;

        ymi = 2*y1 - ys;

    }

    else if(x2 == x1)

    {

        xmi = 2*x1 - xs;

        ymi = ys;

    }

    else

    {

        k1 = (y2-y1)/(x2-x1);

        k2 = (x1-x2)/(y2-y1);

        b1 = y2 - k1*x2;

        b2 = ys - k2*xs;

        xmi = 2*(b1-b2)/(k2-k1) - xs;//     x  

        ymi = k2*(xmi- xs) + ys;//       y

    }

}

void  inst(double xs,double ys,double xe,double ye,double x1,double y1,double x2,double y2)//        。

{

    double k1,k2,b1,b2;//            

    if(xe == xs)

    {

        k2 = (y2-y1)/(x2-x1);

        b2 = y2 - k2*x2;

        xx = xe;

        yy = k2*xx + b2;

        return ;

    }

    if(x2 == x1)

    {

        k1 = (ye-ys)/(xe-xs);

        b1 = ys - k1*xs;

        xx = x2;

        yy = k1*xx + b1;

        return ;

    }

    k1 = (ye-ys)/(xe-xs);

    k2 = (y2-y1)/(x2-x1);

    b1 = ys - k1*xs;

    b2 = y2 - k2*x2;

    xx = (b1-b2)/(k2-k1);

    yy = k1*xx + b1;

}

int main()

{

    double x1,y1,x2,y2,xs,ys,xe,ye;

    int t;

    scanf("%d",&t);

    while(t--)

    {

        scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&xs,&ys,&xe,&ye);

        line(x1,y1,x2,y2,xs,ys);

        inst(xmi,ymi,xe,ye,x1,y1,x2,y2);

        printf("%.3lf %.3lf
",xx+eps,yy+eps); } return 0; } /*
2 1 1 0 0 0 1 -1 0 1 1 0 0 0 1 1 2 */

좋은 웹페이지 즐겨찾기