• <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>
            方法1:過該點(diǎn)作一條射線,然后判斷該射線與三條邊的相交情況;  
              方法2:分別連接P點(diǎn)和三個(gè)頂點(diǎn)A,B,C,然后判斷矢量PA,PB,PC所夾角之和是否為360度,如果是360度則P在三角形內(nèi)  
               
              1.    
              #include   <stdio.h>  
              #include   <math.h>  
               
              struct   TPoint  
              {  
              float   x;  
              float   y;  
              };  
               
              float   area(struct   TPoint   p1,struct   TPoint   p2,struct   TPoint   p3){  
              return   fabs((p1.x-p3.x)*(p2.y-p3.y)-(p2.x-p3.x)*(p1.y-p3.y));  
              }  
               
              float   mul(struct   TPoint   p1,struct   TPoint   p2,struct   TPoint   p0){  
              return((p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y));  
              }  
               
              int   inside(struct   TPoint   tr[],struct   TPoint   p){  
              int   i;  
              for   (i=0;i<3;i++)  
              if   (mul(p,tr[i],tr[(i+1)%3])*mul(p,tr[(i+2)%3],tr[(i+1)%3])>0)  
              return   0;  
              return   1;  
              }  
               
              int   inside2(struct   TPoint   tr[],struct   TPoint   p){  
              if   (fabs(area(tr[0],tr[1],tr[2])-  
                area(p,tr[1],tr[2])-  
                area(tr[0],p,tr[2])-  
                area(tr[0],tr[1],p))<1.0e-20)  
              return   1;  
              else  
              return   0;  
              }  
               
              main(){  
              struct   TPoint   tr[3]={{-1,1},{1,0},{3,0}},p={1,2};  
              printf("algorithm   1:");  
              if   (inside(tr,p))  
              printf("In\n");  
              else  
              printf("Out\n");  
              printf("algorithm   2:");  
              if   (inside2(tr,p))  
              printf("In\n");  
              else  
              printf("Out\n");  
              }  
               
              2  
              就是判斷點(diǎn)到三個(gè)頂點(diǎn)的夾角之和為2*PI  
              //   返回1   表示在那,0表示在外  
              int   inside3(const   struct   TPoint   tr[],   struct   TPoint   p)  
              {  
              TPoint   p0,p1,p2;  
              p0.x   =   tr[0].x   -   p.x   ;     p0.y   =   tr[0].y   -   p.y;  
              p1.x   =   tr[1].x   -   p.x   ;     p1.y   =   tr[1].y   -   p.y;  
              p2.x   =   tr[2].x   -   p.x   ;     p2.y   =   tr[2].y   -   p.y;  
               
              double   arg1   =   acos((p0.x*p1.x   +   p0.y*p1.y)/sqrt(p0.x*p0.x   +   p0.y*p0.y)/sqrt(p1.x*p1.x+p1.y*p1.y));  
              double   arg2   =   acos((p0.x*p2.x   +   p0.y*p2.y)/sqrt(p0.x*p0.x   +   p0.y*p0.y)/sqrt(p2.x*p2.x+p2.y*p2.y));  
              double   arg3   =   acos((p2.x*p1.x   +   p2.y*p1.y)/sqrt(p2.x*p2.x   +   p2.y*p2.y)/sqrt(p1.x*p1.x+p1.y*p1.y));  
               
              if(   fabs(2*3.1415926-arg1-arg2-arg3)<0.0001   )   return   1;  
              return   0;  
              }  
               
            Posted on 2009-11-04 21:07 micheal's tech 閱讀(1833) 評論(0)  編輯 收藏 引用

            只有注冊用戶登錄后才能發(fā)表評論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


            狠狠色伊人久久精品综合网| 国产成人精品久久| 久久久久久a亚洲欧洲aⅴ| 热re99久久精品国产99热| 久久国产精品波多野结衣AV| 久久久精品久久久久影院| 国产精品一久久香蕉国产线看观看| 99久久99久久精品国产片果冻| 中文字幕无码免费久久| 亚洲伊人久久大香线蕉苏妲己| 伊人久久无码精品中文字幕| 99久久亚洲综合精品网站| 四虎国产精品成人免费久久| 国产成人久久久精品二区三区 | 亚洲乱亚洲乱淫久久| 久久久久久免费视频| 久久久久综合国产欧美一区二区| 国产精品99精品久久免费| 亚洲午夜精品久久久久久浪潮| 嫩草影院久久国产精品| 999久久久无码国产精品| 人妻无码αv中文字幕久久琪琪布| 亚洲国产视频久久| 久久国产免费| 精品久久久久久久久免费影院| 中文精品99久久国产 | 伊人久久大香线蕉综合5g| 国产激情久久久久影院老熟女| 国产精品久久久久aaaa| 精品国产乱码久久久久久郑州公司| 午夜精品久久久久久毛片| 久久久久久久97| 草草久久久无码国产专区| 国产精品久久成人影院| 久久国产乱子伦精品免费强| 久久综合久久综合久久| 久久久久亚洲AV无码永不| 精品久久久久久亚洲精品 | 久久精品免费全国观看国产| 人妻精品久久久久中文字幕| 色狠狠久久综合网|