zoukankan      html  css  js  c++  java
  • how to determinepointinlinepolyno

    // Globals which should be set before calling this function:
        //
        // int polySides = how many corners the polygon has
        // float polyX[] = horizontal coordinates of corners
        // float polyY[] = vertical coordinates of corners
        // float x, y = point to be tested
        //
        // (Globals are used in this example for purposes of speed. Change as
        // desired.)
        //
        // The function will return YES if the point x,y is inside the polygon, or
        // NO if it is not. If the point is exactly on the edge of the polygon,
        // then the function may return YES or NO.
        //
        // Note that division by zero is avoided because the division is protected
        // by the "if" clause which surrounds it.
    
        private boolean pointInPolygon(float x, float y) {
            float[] pots = { bitmapRectF.left, bitmapRectF.top, bitmapRectF.right, bitmapRectF.top, bitmapRectF.right, bitmapRectF.bottom, bitmapRectF.left, bitmapRectF.bottom };
            matrix1.mapPoints(pots);
            float polyX[] = {pots[0],pots[2],pots[4],pots[6]};
            float polyY[] = {pots[1],pots[3],pots[5],pots[7]};
            int polySides = 4;
            int i, j = polySides - 1;
            boolean oddNodes = false;
    
            for (i = 0; i < polySides; i++) {
                if ((polyY[i] < y && polyY[j] >= y || polyY[j] < y && polyY[i] >= y)
                        && (polyX[i] <= x || polyX[j] <= x)) {
                    oddNodes ^= (polyX[i] + (y - polyY[i]) / (polyY[j] - polyY[i])
                            * (polyX[j] - polyX[i]) < x);
                }
                j = i;
            }
    
            return oddNodes;
        }
  • 相关阅读:
    开关门(结构体)
    洗牌问题(找规律)
    七夕节(hd1215)干嘛今天做这题T_T
    三角形(hd1249)
    寒冰王座(hd1248)
    钱币兑换问题(hd1284)
    计算机模拟(hd1283)
    回文数猜想(hd1282)
    贪吃蛇代码
    变形课hd1181(DFS)
  • 原文地址:https://www.cnblogs.com/slider/p/3056104.html
Copyright © 2011-2022 走看看