相关疑难解决方法(0)

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万
查看次数

标签 统计

.net ×1

algorithm ×1

c# ×1