Skip to content

判断一个点是不是在多边形内部 #53

@wangning0

Description

@wangning0
function _isInsidePolygon(pt, poly) {  
    for (var c = false, i = -1, l = poly.length, j = l - 1; ++i < l; j = i)  
        ((poly[i].y <= pt.y && pt.y < poly[j].y) || (poly[j].y <= pt.y && pt.y < poly[i].y))  
        && (pt.x < (poly[j].x - poly[i].x) * (pt.y - poly[i].y) / (poly[j].y - poly[i].y) + poly[i].x)  
        && (c = !c);  
    return c;  
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions