天气与日历 切换到窄版

 找回密码
 立即注册
中国膜结构网
十大进口膜材评选 十大国产膜材评选 十大膜结构设计评选 十大膜结构公司评选
查看: 53|回复: 0

IsPointInBoundary在边界内

[复制链接]
  • TA的每日心情
    开心
    昨天 15:13
  • 签到天数: 153 天

    [LV.7]常住居民III

    3456

    主题

    553

    回帖

    214748万

    积分

    管理员

    中国膜结构网www.mjgou.com

    积分
    2147483647
    QQ
    发表于 2024-7-24 22:43:53 | 显示全部楼层 |阅读模式
    1.                                     //-------------------------------------//
    2.                                     //  IsPointInBoundary                  //
    3.                                     //-------------------------------------//
    4. int IsPointInBoundary( ads_point pPt, ads_point *pOutline, int nNum, int fAllowOnPerimeter )
    5. {
    6.     int nNumLft;        // Number of Boundary Intersections to the Left of this Point
    7.     int nNumRgt;        // Number of Boundary Intersections to the Right of this Point
    8.     int nKnt;
    9.     int nPrev;
    10.     int nNext;
    11.     ads_point pPt1;     // Used with acdbInters()
    12.     ads_point pInt;     // Intersection Point returned by acdbInters()

    13.     double dTol = 0.1 * pSettings.dMetricScl;

    14.         // Create pPt1 to Be Horzontal from pPt
    15.     Cpoint( pPt1, pPt );
    16.     pPt1[X] += 120.0;

    17.         // For Each Line of the Outline, Intersect a Horizontal line through pPt
    18.     nNumLft = 0;
    19.     nNumRgt = 0;
    20.     for( nKnt=1; nKnt<nNum; nKnt++ ) {
    21.             // Make sure there's potential for a horizontal intersection
    22.         if ( pOutline[nKnt-1][Y] + dTol < pPt[Y] && pOutline[nKnt][Y] + dTol < pPt[Y] ) {
    23.             continue;
    24.         }
    25.         if ( pOutline[nKnt-1][Y] - dTol > pPt[Y] && pOutline[nKnt][Y] - dTol > pPt[Y] ) {
    26.             continue;
    27.         }

    28.             // Check for Horizontal Segment
    29.         if ( fabs( pOutline[nKnt][Y] - pPt[Y] ) < 0.1 && fabs( pOutline[nKnt-1][Y] - pPt[Y] ) < 0.1 ) {
    30.                 // If the Point is On this Segment, then use the fAllowOnPerimeter Variable
    31.             if ( IsPointOnLine( pPt, pOutline[nKnt-1], pOutline[nKnt], 0.05 )) {
    32.                 if ( fAllowOnPerimeter ) {
    33.                     return( TRUE );
    34.                 } else {
    35.                     return( FALSE );
    36.                 }
    37.             }

    38.                 // Horizontal, if the Points Before and After this Segment are both Below or both Above,
    39.                 // Skip this segment
    40.             if ( nKnt-2 < 0 ) {
    41.                 if ( AboutEqualPts( pOutline[nNum-1], pOutline[0] )) {
    42.                     nPrev = nNum - 2;
    43.                 } else {
    44.                     nPrev = nNum - 1;
    45.                 }
    46.             } else {
    47.                 nPrev = nKnt - 2;
    48.             }
    49.             if ( nKnt < nNum-1 ) {
    50.                 nNext = nKnt + 1;
    51.             } else {
    52.                 nNext = 1;
    53.             }
    54.             if ( pOutline[nPrev][Y] + dTol < pPt[Y] && pOutline[nNext][Y] + dTol < pPt[Y] ) {
    55.                 continue;
    56.             } else if ( pOutline[nPrev][Y] + dTol > pPt[Y] && pOutline[nNext][Y] + dTol > pPt[Y] ) {
    57.                 continue;
    58.             }
    59.         }

    60.             // Check for Segment totally to the Left
    61.         if ( pOutline[nKnt-1][X] + dTol < pPt[X] && pOutline[nKnt][X] + dTol < pPt[X] ) {
    62.             if ( fabs( pOutline[nKnt][Y] - pPt[Y] ) < 0.1 ) {
    63.                 if ( fabs( pOutline[nKnt-1][Y] - pPt[Y] ) > 0.1 ) {
    64.                         // Skip this if it's a Horizontal Segment
    65.                     Cpoint( pInt, pOutline[nKnt] );
    66.                     goto ProcessEndPoint;
    67.                 }
    68.             }
    69.             nNumLft++;
    70.             continue;
    71.         }

    72.             // Check for Segment totally to the right
    73.         if ( pOutline[nKnt-1][X] - dTol > pPt[X] && pOutline[nKnt][X] - dTol > pPt[X] ) {
    74.             if ( fabs( pOutline[nKnt][Y] - pPt[Y] ) < 0.1 ) {
    75.                 if ( fabs( pOutline[nKnt-1][Y] - pPt[Y] ) > 0.1 ) {
    76.                         // Skip this if it's a Horizontal Segment
    77.                     Cpoint( pInt, pOutline[nKnt] );
    78.                     goto ProcessEndPoint;
    79.                 }
    80.             }
    81.             nNumRgt++;
    82.             continue;
    83.         }

    84.             // If the Point is On this Segment, then use the fAllowOnPerimeter Variable
    85.         if ( IsPointOnLine( pPt, pOutline[nKnt-1], pOutline[nKnt], 0.05 )) {
    86.             if ( fAllowOnPerimeter ) {
    87.                 return( TRUE );
    88.             } else {
    89.                 return( FALSE );
    90.             }
    91.         }

    92.             // Intersect with the Segment
    93.         if ( acdbInters( pPt, pPt1, pOutline[nKnt-1], pOutline[nKnt], FALSE, pInt ) != RTNORM ) {
    94.             continue;
    95.         }
    96.             // If it's one of the Vertex Points, process it Differently
    97.         if ( AboutEqualPts( pInt, pOutline[nKnt] )) {
    98. ProcessEndPoint:
    99.             if ( pOutline[nKnt-1][Y] + dTol < pPt[Y] ) {
    100.                 if ( nKnt < nNum-1 ) {
    101.                     if ( pOutline[nKnt+1][Y] + dTol < pPt[Y] || fabs( pOutline[nKnt+1][Y] - pPt[Y] ) < 0.1 ) {
    102.                         goto ProcessInt;
    103.                     }
    104.                 } else {
    105.                     if ( pOutline[1][Y] + dTol < pPt[Y] || fabs( pOutline[1][Y] - pPt[Y] ) < 0.1 ) {
    106.                         goto ProcessInt;
    107.                     }
    108.                 }
    109.             } else {
    110.                 if ( nKnt < nNum-1 ) {
    111.                     if ( pOutline[nKnt+1][Y] - dTol > pPt[Y] || fabs( pOutline[nKnt+1][Y] - pPt[Y] ) < 0.1 ) {
    112.                         goto ProcessInt;
    113.                     }
    114.                 } else {
    115.                     if ( pOutline[1][Y] - dTol > pPt[Y] || fabs( pOutline[1][Y] - pPt[Y] ) < 0.1 ) {
    116.                         goto ProcessInt;
    117.                     }
    118.                 }
    119.             }
    120.         } else {
    121. ProcessInt:
    122.                 // See if it's to the Left or Right
    123.             if ( pInt[X] < pPt[X] ) {
    124.                 nNumLft++;
    125.             } else {
    126.                 nNumRgt++;
    127.             }
    128.         }
    129.     }

    130. //acutPrintf( _T("pPt=(%f,%f), nNumLft=%d, nNumRgt=%d\n"), pPt[X], pPt[Y], nNumLft, nNumRgt );
    131.         // To be Inside the Boundary, both nNumLft and nNumRgt MUST be ODD
    132.     if (( nNumLft % 2 ) == 0 ) {
    133.         return( FALSE );
    134.     }
    135.     if (( nNumRgt % 2 ) == 0 ) {
    136.         return( FALSE );
    137.     }

    138.     return( TRUE );
    139. }

    复制代码

     

     

     

     

    IsPointInBoundary在边界内
    中国膜结构网打造全中国最好的膜结构综合平台 ,统一协调膜结构设计,膜结构施工,膜材采购,膜材定制,膜结构预算全方位服务。 中国空间膜结构协会合作单位。
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    QQ|Archiver|手机版|中国膜结构网|中国膜结构协会|进口膜材|国产膜材|ETFE|PVDF|PTFE|设计|施工|安装|车棚|看台|污水池| |网站地图

    GMT+8, 2024-9-8 09:25 , Processed in 0.086690 second(s), 23 queries .

    Powered by Discuz! X3.5

    © 2001-2024 Discuz! Team.

    快速回复 返回顶部 返回列表