相关疑难解决方法(0)

如何确定2D点是否在多边形内?

我正在尝试在多边形算法中创建一个快速 2D点,用于命中测试(例如Polygon.contains(p:Point)).对于有效技术的建议将不胜感激.

graphics performance polygon collision-detection point-in-polygon

473
推荐指数
15
解决办法
26万
查看次数

C#指向多边形

我正在尝试确定一个点是否在多边形内.Polygon由Point对象数组定义.我可以很容易地弄清楚该点是否在多边形的有界框内,但我不知道如何判断它是否在实际多边形内.如果可能的话,我只想使用C#和WinForms.我宁愿不打电话给OpenGL或其他什么来做这个简单的任务.

这是我到目前为止的代码:

private void CalculateOuterBounds()
{
    //m_aptVertices is a Point[] which holds the vertices of the polygon.
    // and X/Y min/max are just ints
    Xmin = Xmax = m_aptVertices[0].X;
    Ymin = Ymax = m_aptVertices[0].Y;

    foreach(Point pt in m_aptVertices)
    {
        if(Xmin > pt.X)
            Xmin = pt.X;

        if(Xmax < pt.X)
            Xmax = pt.X;

        if(Ymin > pt.Y)
            Ymin = pt.Y;

        if(Ymax < pt.Y)
            Ymax = pt.Y;
    }
}

public bool Contains(Point pt)
{
    bool bContains = true; //obviously wrong at the moment :) …
Run Code Online (Sandbox Code Playgroud)

.net c# algorithm

35
推荐指数
7
解决办法
6万
查看次数

C# - 从没有API的纬度/经度获取国家/地区

是否可以使用C#库或有关地理坐标的更新数据库来获取纬度和经度的国家/地区名称而不使用像Google Maps的JavaScript API这样的API?

c# geolocation geonames

7
推荐指数
2
解决办法
3834
查看次数