• UVa 11437


    了解矢量为交点的坐标。

    #include <iostream>
    #include <cstring>
    #include <cstdio>
    #include <algorithm>
    #include <cstdlib>
    #include <cmath>
    #define eqs 1e-8
    using namespace std;
    double a = 2.0/3;
    double b = 1.0/3;
    int main()
    {
        //freopen("data.txt","r",stdin);
        double xax,xay;
        double xbx,xby;
        double xcx,xcy;
        double xfx,xfy;
        double xex,xey;
        double xdx,xdy;
        double xpx,xpy;
        double xqx,xqy;
        double xrx,xry;
        int t;
        scanf("%d",&t);
        while(t--)
        {
            scanf("%lf %lf",&xax,&xay);
            scanf("%lf %lf",&xbx,&xby);
            scanf("%lf %lf",&xcx,&xcy);
            xfx = a*xbx+b*xax; xfy = a*xby+b*xay;
            xex = a*xax+b*xcx; xey = a*xay+b*xcy;
            xdx = a*xcx+b*xbx; xdy = a*xcy+b*xby;
            double linadk,linadb;
            int sumad=0;
            if(fabs(xax-xdx-0)<=eqs)
            {
                linadb = xax;
                sumad = 0;
            }else if(fabs(xay-xdy-0)<=eqs)
            {
                linadb = xay;
                sumad = 1;
            }else
            {
                sumad = 2;
                linadk = (xay-xdy)/(xax-xdx);
                linadb = xay - linadk * xax;
            }
            double linfck,linfcb;
            int sumfc=0;
            if(fabs(xfx-xcx-0)<=eqs)
            {
                linfcb = xfx;
                sumfc = 0;
            }else if(fabs(xfy-xcy-0)<=eqs)
            {
                linfcb = xay;
                sumfc = 1;
            }else
            {
                sumfc = 2;
                linfck = (xfy-xcy)/(xfx-xcx);
                linfcb = xfy - linfck * xfx;
            }
            double linbek,linbeb;
            int sumbe=0;
            if(fabs(xbx-xex-0)<=eqs)
            {
                linbeb = xbx;
                sumbe = 0;
            }else if(fabs(xby-xey-0)<=eqs)
            {
                linbeb = xby;
                sumbe = 1;
            }else
            {
                sumbe = 2;
                linbek = (xby-xey)/(xbx-xex);
                linbeb = xby - linbek * xbx;
            }
            if(sumfc==0)
            {
                xrx = linfcb;
                if(sumad==1)
                {
                    xry = linadb;
                }else if(sumad==2)
                {
                    xry = linadk*xrx+linadb;
                }
                xqx = linfcb;
                if(sumbe==1)
                {
                    xqy = linbeb;
                }else if(sumbe==2)
                {
                    xqy = linbek*xqx+linbeb;
                }
            }else if(sumfc==1)
            {
                xry = linfcb;
                if(sumad==0)
                {
                    xrx = linadb;
                }else if(sumad==2)
                {
                    xrx = (xry-linadb)/linadk;
                }
                xqy = linfcb;
                if(sumbe==0)
                {
                    xqx = linbeb;
                }else if(sumbe==2)
                {
                    xqx = (xqy-linbeb)/linbek;
                }
            }else
            {
                if(sumad==0)
                {
                    xrx = linadb;
                    xry = xrx*linfck+linfcb;
                }else if(sumad==1)
                {
                    xry = linadb;
                    xrx = (xry-linfcb)/linfck;
                }else if(sumad==2)
                {
                    xrx = (linfcb-linadb)/(linadk-linfck);
                    xry = linfck * xrx + linfcb;
                }
                if(sumbe==0)
                {
                    xqx = linbeb;
                    xqy = xqx*linfck+linfcb;
                }else if(sumbe==1)
                {
                    xqy = linbeb;
                    xqx = (xqy-linfcb)/linfck;
                }else if(sumad==2)
                {
                    xqx = (linfcb-linbeb)/(linbek-linfck);
                    xqy = linfck * xqx + linfcb;
                }
            }
            if(sumbe==0)
            {
                xpx = linbeb;
                if(sumad==1)
                {
                    xpy = linadb;
                }else if(sumad==2)
                {
                    xpy = linadk*xpx+linadb;
                }
            }else if(sumbe==1)
            {
                xpy = linbeb;
                if(sumad==0)
                {
                    xpx = linadb;
                }else if(sumad==2)
                {
                    xpx = (xpy-linadb)/linadk;
                }
            }else if(sumbe==2)
            {
                if(sumad==0)
                {
                    xpx = linadb;
                    xpy = xrx*linbek+linbeb;
                }else if(sumad==1)
                {
                    xpy = linadb;
                    xpx = (xry-linbeb)/linbek;
                }else if(sumad==2)
                {
                    xpx = (linbeb-linadb)/(linadk-linbek);
                    xpy = linbek * xpx + linbeb;
                }
            }
            double ans = 0;
            ans+=(xpx*xqy-xpy*xqx);
            ans+=(xqx*xry-xqy*xrx);
            ans+=(xrx*xpy-xry*xpx);
            if(ans<0)
            {
                ans = ans * -1;
            }
            ans = ans/2;
            printf("%.0lf
    ",ans);
        }
        return 0;
    }
    


    版权声明:本文博客原创文章,博客,未经同意,不得转载。

  • 相关阅读:
    LVGL初步移植
    为什么javac后加.java,java后不加.class?
    为什么内部类可以访问外部类的私有属性?
    Optional类与使用==判断null有什么区别?使用Optional类有什么优势?
    注释中的Unicode编码也会被转义
    用反射编写泛型数组
    JDBC与JPA--初学JPA
    抽象类与接口
    面向对象——多态
    面向对象——封装(隐藏)
  • 原文地址:https://www.cnblogs.com/lcchuguo/p/4623512.html
Copyright © 2020-2023  润新知