• <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:過該點作一條射線,然后判斷該射線與三條邊的相交情況;  
              方法2:分別連接P點和三個頂點A,B,C,然后判斷矢量PA,PB,PC所夾角之和是否為360度,如果是360度則P在三角形內  
               
              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  
              就是判斷點到三個頂點的夾角之和為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 閱讀(1829) 評論(0)  編輯 收藏 引用
            久久人人爽人人爽人人爽 | 91精品国产色综久久| 国产成人精品免费久久久久| 欧美精品一区二区精品久久| 久久久久久亚洲精品无码| 无码任你躁久久久久久久| 久久久久人妻一区二区三区vr| 久久青青草原综合伊人| 久久久无码精品亚洲日韩软件| 久久综合给久久狠狠97色| 97久久精品人人做人人爽| 一本色综合久久| 99久久精品免费看国产一区二区三区| 国产精品99久久精品爆乳| 久久国产亚洲精品麻豆| 色综合久久综合中文综合网| 久久93精品国产91久久综合| 久久这里只有精品久久| 精品熟女少妇AV免费久久| 亚洲国产精品婷婷久久| 亚洲人成网亚洲欧洲无码久久| 久久久久国产视频电影| 精品999久久久久久中文字幕| 久久国内免费视频| 看全色黄大色大片免费久久久 | 精品久久久久久亚洲精品| 色天使久久综合网天天| 国产高潮国产高潮久久久91| 久久精品国产精品亚洲毛片| 久久精品国产99国产精品导航| 久久亚洲2019中文字幕| 99久久国产免费福利| 日本道色综合久久影院| 高清免费久久午夜精品| 久久国产精品久久国产精品| 蜜臀av性久久久久蜜臀aⅴ麻豆| 亚洲国产精品无码久久青草| 亚洲精品乱码久久久久久不卡| 国产99久久久国产精免费| 久久亚洲综合色一区二区三区| 久久91综合国产91久久精品|