• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            Tauruser

            Enjoy Every Day
            posts - 34, comments - 95, trackbacks - 0, articles - 5
              C++博客 :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

            05年寫的直線裁剪算法

            Posted on 2007-01-28 10:28 Tauruser 閱讀(2771) 評論(2)  編輯 收藏 引用 所屬分類: 計算機(jī)圖形學(xué)
            頭文件<line.h>

            #pragma?once
            #include?
            "afx.h"
            #include?
            "atltypes.h"
            /*
            ?*?Powered?by?Tauruser
            ?*?Tauruser~gmail.com
            ?*?Written?on?2005.12
            ?*?歡迎轉(zhuǎn)載,請說明出處
            ?
            */
            ?
            class?CLine?:
            ????
            public?CObject
            {
            ????DECLARE_SERIAL?(CLine)
            public:
            ????CLine(
            void);
            ????
            ~CLine(void);
            private:
            ????CPoint?m_ptFrom;
            private:
            ????CPoint?m_ptTo;
            public:
            ????CLine(CPoint?ptFrom,?CPoint?ptTo);
            ????
            void?Draw(CDC*?pDC);
            ????
            void?Serialize(CArchive&?ar);
            ????CLine
            *?SetLine(CPoint?ptFrom,?CPoint?ptTo);
            ????
            //?剪裁線段,參數(shù)為窗口左上角和右下角坐標(biāo),當(dāng)線段在窗口內(nèi)返回TRUE,否則

            FALSE
            ????
            bool?Cut(CPoint?ptUpLeft,?CPoint?ptDownRight);
            }
            ;

            源碼<line.cpp>

            #include?"StdAfx.h"
            #include?
            ".\line.h"
            /*
            ?*?Powered?by?Tauruser
            ?*?Tauruser~gmail.com
            ?*?Written?on?2005.12
            ?*?歡迎轉(zhuǎn)載,請說明出處
            ?
            */
            ?
            IMPLEMENT_SERIAL?(CLine,CObject,
            1)
            CLine::CLine(
            void)
            :?m_ptFrom(
            0)
            ,?m_ptTo(
            0)
            {
            }


            CLine::
            ~CLine(void)
            {
            }


            CLine::CLine(CPoint?ptFrom,?CPoint?ptTo)
            {
            ????m_ptFrom
            =ptFrom;
            ????m_ptTo
            =ptTo;
            }


            void?CLine::Draw(CDC*?pDC)
            {
            ????pDC
            ->MoveTo(m_ptFrom);
            ????pDC
            ->LineTo(m_ptTo);
            }


            void?CLine::Serialize(CArchive&?ar)
            {
            ????CObject::Serialize(ar);
            ????
            if(ar.IsStoring())
            ????????ar
            <<m_ptFrom<<m_ptTo;
            ????
            else
            ????????ar
            >>m_ptFrom>>m_ptTo;
            }


            CLine
            *?CLine::SetLine(CPoint?ptFrom,?CPoint?ptTo)
            {
            ????m_ptFrom
            =ptFrom;
            ????m_ptTo
            =ptTo;
            ????
            return?this;
            }


            //?剪裁線段,參數(shù)為窗口左上角和右下角坐標(biāo),當(dāng)線段在窗口內(nèi)返回TRUE,否則FALSE
            bool?CLine::Cut(CPoint?ptUpLeft,?CPoint?ptDownRight)
            {
            ????
            //long?iA,iB,iC,iD,iXl,iXr,iYt,iYb;?
            ????const?long?iA(m_ptFrom.x),?iB(m_ptFrom.y),?iC(m_ptTo.x),?iD(m_ptTo.y);
            ????
            long?iXl=ptUpLeft.x,?iXr=ptDownRight.x,?iYt=ptUpLeft.y,?iYb=ptDownRight.y;
            ????
            int?temp;
            ????
            if?(iXl>iXr)?
            ????
            {
            ????????temp
            =iXl;
            ????????iXl
            =iXr;
            ????????iXr
            =temp;
            ????}

            ????
            if(iYb>iYt)
            ????
            {
            ????????temp
            =iYb;
            ????????iYb
            =iYt;
            ????????iYt
            =temp;
            ????}


            ????
            if(iXl<=iA?&&?iA<=iXr)
            ????
            {
            ????????
            if(iYb<=iB?&&?iB<=iYt)
            ????????
            {????;//m_ptFrom保持原值
            ????????}
            else?if(iB<iYb?&&?iD<iYb)?
            ????????????
            return?false;//與窗口無交.
            ????????else?if?(iB<iYb?&&?iD>=iYb)
            ????????
            {
            ????????????
            //1.2
            ????????????int?x;
            ????????????x
            =iA-((iB-iYb)*(iA-iC)/(iB-iD));
            ????????????
            if(iXl<=x?&&?x<=iXr)//檢驗x的有校性
            ????????????{
            ????????????????m_ptFrom.x
            =x;
            ????????????????m_ptFrom.y
            =iYb;

            ????????????}
            else?return?false;//否則無交點(diǎn)

            ????????}
            else?if(iB>iYt?&&?iD>iYt)?????return?false;//與窗口無交
            ????????else?if(iB>iYt?&&?iD<=iYt)
            ????????
            {????
            ????????????
            //1.3
            ????????????int?x;
            ????????????x
            =iA-((iB-iYt)*(iA-iC)/(iB-iD));//檢驗x的有校性?
            ????????????if(iXl<=x?&&?x<=iXr)//
            ????????????{
            ????????????????m_ptFrom.x
            =x;
            ????????????????m_ptFrom.y
            =iYt;
            ????????????}
            else?return?false;//否則無交點(diǎn)

            ????????}

            ????????

            ????}
            else?if(iA<iXl)
            ????
            {
            ????????
            if(iC<iXl)?return?false;
            ????????
            else
            ????????
            {
            ????????????
            int?y;
            ????????????y
            =iB-((iA-iXl)*(iB-iD)/(iA-iC));

            ????????????
            if(iYb<=y?&&?y<=iYt)
            ????????????
            {
            ????????????????m_ptFrom.x
            =iXl;
            ????????????????m_ptFrom.y
            =y;
            ????????????}
            else?if?((y<iYb?||?y>iYt)?&&?(iYb<=iB?&&?iB<=iYt))?
            ????????????
            {
            ????????????????
            return?false;
            ????????????}

            ????????????
            else?if(y<iYb?||?iB<iYb)
            ????????????
            {
            ????????????????
            //1.2
            ????????????????int?x;
            ????????????????x
            =iA-((iB-iYb)*(iA-iC)/(iB-iD));
            ????????????????
            if(iXl<=x?&&?x<=iXr)//檢驗x的有校性
            ????????????????{
            ????????????????????m_ptFrom.x
            =x;
            ????????????????????m_ptFrom.y
            =iYb;
            ????????????????}
            else?return?false;//否則無交點(diǎn)
            ????????????}

            ????????????
            else?if(y>iYt?||?iB>iYt)
            ????????????
            {
            ????????????????
            //1.3
            ????????????????int?x;
            ????????????????x
            =iA-((iB-iYt)*(iA-iC)/(iB-iD));//檢驗x的有校性?
            ????????????????if(iXl<=x?&&?x<=iXr)//
            ????????????????{
            ????????????????????m_ptFrom.x
            =x;
            ????????????????????m_ptFrom.y
            =iYt;
            ????????????????}
            else?return?false;//否則無交點(diǎn)
            ????????????}

            ????????}


            ????}
            else?if(iA>iXr)
            ????
            {
            ????????
            if(iC>iXr)?return?false;//
            ????????else
            ????????
            {
            ????????????
            int?y;
            ????????????y
            =iB-((iA-iXr)*(iB-iD)/(iA-iC));
            ????????????
            ????????????
            if(iYb<=y?&&?y<=iYt)
            ????????????
            {
            ????????????????m_ptFrom.x
            =iXr;
            ????????????????m_ptFrom.y
            =y;
            ????????????}
            else?if?((y<iYb?||?y>iYt)?&&?(iYb<=iB?&&?iB<=iYt))?
            ????????????
            {
            ????????????????
            return?false;
            ????????????}

            ????????????
            else?if(y<iYb?||?iB<iYb)
            ????????????
            {
            ????????????????
            //1.2
            ????????????????int?x;
            ????????????????x
            =iA-((iB-iYb)*(iA-iC)/(iB-iD));
            ????????????????
            if(iXl<=x?&&?x<=iXr)//檢驗x的有校性
            ????????????????{
            ????????????????????m_ptFrom.x
            =x;
            ????????????????????m_ptFrom.y
            =iYb;
            ????????????????}
            else?return?false;//否則無交點(diǎn)
            ????????????}

            ????????????
            else?if(y>iYt?||?iB>iYt)
            ????????????
            {
            ????????????????
            //1.3
            ????????????????int?x;
            ????????????????x
            =iA-((iB-iYt)*(iA-iC)/(iB-iD));//檢驗x的有校性?
            ????????????????if(iXl<=x?&&?x<=iXr)//
            ????????????????{
            ????????????????????m_ptFrom.x
            =x;
            ????????????????????m_ptFrom.y
            =iYt;
            ????????????????}
            else?return?false;//否則無交點(diǎn)
            ????????????}


            ????????}


            ????}

            //////////////////////////////////////////////////////////////////////////////////

            ????
            if(iXl<=iC?&&?iC<=iXr)
            ????
            {
            ????????
            if(iYb<=iD?&&?iD<=iYt)?
            ????????????
            return?true;//m_ptFrom保持原值
            ????????else?if(iB<iYb?&&?iD<iYb)?return?false;//與窗口無交.
            ????????else?if(iD<iYb?&&?iB>=iYb)
            ????????
            {
            ????????????
            //1.2
            ????????????int?x;
            ????????????x
            =iA-((iB-iYb)*(iA-iC)/(iB-iD));
            ????????????
            if(iXl<=x?&&?x<=iXr)//檢驗x的有校性
            ????????????{
            ????????????????m_ptTo.x
            =x;
            ????????????????m_ptTo.y
            =iYb;
            ????????????????
            return?true;
            ????????????}
            else?return?false;//否則無交點(diǎn)
            ????????}
            else?if(iB>iYt?&&?iD>iYt)?return?false;
            ????????
            else?if(iD>iYt?&&?iB<=iYt)
            ????????
            {????
            ????????????
            //1.3
            ????????????int?x;
            ????????????x
            =iA-((iB-iYt)*(iA-iC)/(iB-iD));//檢驗x的有校性?
            ????????????if(iXl<=x?&&?x<=iXr)//
            ????????????{
            ????????????????m_ptTo.x
            =x;
            ????????????????m_ptTo.y
            =iYt;
            ????????????????
            return?true;
            ????????????}
            else?return?false;//否則無交點(diǎn)

            ????????}

            ????????

            ????}
            else?if(iC<iXl)
            ????
            {
            ????????
            if(iA<iXl)?return?false;
            ????????
            else
            ????????
            {
            ????????????
            int?y;
            ????????????y
            =iB-((iA-iXl)*(iB-iD)/(iA-iC));

            ????????????
            if(iYb<=y?&&?y<=iYt)
            ????????????
            {
            ????????????????m_ptTo.x
            =iXl;
            ????????????????m_ptTo.y
            =y;
            ????????????????
            return?true;
            ????????????}
            else?if?((y<iYb?||?y>iYt)?&&?(iYb<=iD?&&?iD<=iYt))?
            ????????????
            {
            ????????????????
            return?false;
            ????????????}

            ????????????
            else?if(y<iYb?||?iB<iYb)
            ????????????
            {
            ????????????????
            //1.2
            ????????????????int?x;
            ????????????????x
            =iA-((iB-iYb)*(iA-iC)/(iB-iD));
            ????????????????
            if(iXl<=x?&&?x<=iXr)//檢驗x的有校性
            ????????????????{
            ????????????????????m_ptTo.x
            =x;
            ????????????????????m_ptTo.y
            =iYb;
            ????????????????????
            return?true;
            ????????????????}
            else?return?false;//否則無交點(diǎn)
            ????????????}

            ????????????
            else?if(y>iYt?||?iB>iYt)
            ????????????
            {
            ????????????????
            //1.3
            ????????????????int?x;
            ????????????????x
            =iA-((iB-iYt)*(iA-iC)/(iB-iD));//檢驗x的有校性?
            ????????????????if(iXl<=x?&&?x<=iXr)//
            ????????????????{
            ????????????????????m_ptTo.x
            =x;
            ????????????????????m_ptTo.y
            =iYt;
            ????????????????????
            return?true;
            ????????????????}
            else?return?false;//否則無交點(diǎn)
            ????????????}

            ????????}


            ????}
            else?if(iC>iXr)
            ????
            {
            ????????
            if(iA>iXr)?return?false;//
            ????????else
            ????????
            {
            ????????????
            int?y;
            ????????????y
            =iB-((iA-iXr)*(iB-iD)/(iA-iC));
            ????????????
            ????????????
            if(iYb<=y?&&?y<=iYt)
            ????????????
            {
            ????????????????m_ptTo.x
            =iXr;
            ????????????????m_ptTo.y
            =y;
            ????????????????
            return?true;
            ????????????}
            else?if?((y<iYb?||?y>iYt)?&&?(iYb<=iD?&&?iD<=iYt))?
            ????????????
            {
            ????????????????
            return?false;
            ????????????}

            ????????????
            else?if(y<iYb?||?iD<iYb)
            ????????????
            {
            ????????????????
            //1.2
            ????????????????int?x;
            ????????????????x
            =iA-((iB-iYb)*(iA-iC)/(iB-iD));
            ????????????????
            if(iXl<=x?&&?x<=iXr)//檢驗x的有校性
            ????????????????{
            ????????????????????m_ptTo.x
            =x;
            ????????????????????m_ptTo.y
            =iYb;
            ????????????????????
            return?true;
            ????????????????}
            else?return?false;//否則無交點(diǎn)
            ????????????}

            ????????????
            else?if(y>iYt?||?iB>iYt)
            ????????????
            {
            ????????????????
            //1.3
            ????????????????int?x;
            ????????????????x
            =iA-((iB-iYt)*(iA-iC)/(iB-iD));//檢驗x的有校性?
            ????????????????if(iXl<=x?&&?x<=iXr)//
            ????????????????{
            ????????????????????m_ptTo.x
            =x;
            ????????????????????m_ptTo.y
            =iYt;
            ????????????????????
            return?true;
            ????????????????}
            else?return?false;//否則無交點(diǎn)
            ????????????}


            ????????}


            ????}

            ????
            return?true;
            ????
            }



            Feedback

            # re: 05年寫的直線裁剪算法  回復(fù)  更多評論   

            2007-06-30 13:18 by hello007@126.com
            好,謝謝

            # re: 05年寫的直線裁剪算法  回復(fù)  更多評論   

            2010-03-01 00:28 by 啊啊啊啊啊啊
            你這個算法也太復(fù)雜了吧
            热久久国产精品| 久久精品国产99国产精品澳门| 青青草国产精品久久久久| 香蕉久久夜色精品升级完成| 综合久久久久久中文字幕亚洲国产国产综合一区首| 亚洲精品无码久久久久久| 久久精品国产久精国产果冻传媒| 污污内射久久一区二区欧美日韩| 国产综合成人久久大片91| 国产精品久久久天天影视香蕉| 亚洲国产成人久久综合一| 青青草原综合久久| 久久精品国产一区二区 | 色偷偷88欧美精品久久久| 久久精品国产亚洲av瑜伽| 婷婷久久综合| 亚洲av成人无码久久精品| 久久综合九色综合网站| 国产精品久久国产精品99盘| 色偷偷888欧美精品久久久| 国产99久久九九精品无码| 色偷偷88欧美精品久久久| 久久婷婷五月综合成人D啪| 亚洲中文久久精品无码| 国产99久久精品一区二区| 成人国内精品久久久久影院VR| 久久久精品人妻无码专区不卡| 麻豆久久久9性大片| 色综合久久久久无码专区| 青青草原1769久久免费播放| 久久亚洲天堂| 久久丫精品国产亚洲av不卡| 国产亚洲美女精品久久久| 99久久香蕉国产线看观香| 国产成人精品久久免费动漫| 欧美大战日韩91综合一区婷婷久久青草| 久久精品无码一区二区WWW| 久久国产成人精品麻豆| 综合久久一区二区三区 | 精品久久人妻av中文字幕| 色综合久久88色综合天天|