我现在正在开发一个图形处理的软件,其中有关于判断凸多边形的问题。我现在是自己写了一个算法判断是否为凸多边形(本身的线段互不相交、对于任一线段,其他的点都在左侧或都在右侧),而这种做法用户不认可,让我调查GDI中现在的API函数,有谁知道GDI中是否有关于判断一组点所构成的多边形是凸多边形的API函数。多谢指教~

解决方案 »

  1.   

    // 功能:判断凹凸多边形。 2005.1.18.
    // lNumPoint--》多边形的点数;
    // PL3DTop--》多边形的顶点数组,点序以逆时针排序;
    // 返回值为true,表示该多边形为凹多边形,否则为凸多边形。
    bool IsConcavePolygon(long lNumPoint, CPolyLine3D& PL3DTop)
    {
    int i, i1, j1;
    double dAxisCos[3][3];
    CPoint3D pt0, pt2, pt5;
    CPoint3DArray Point3DArray; if(lNumPoint<4)return false;
    // 判断凹凸多边形。
    Point3DArray.SetSize(3);
    for(i=0;i<lNumPoint-1;i++)
    {
    i1 = i+1;
    Point3DArray[0].x  = PL3DTop.P3Ds[i].P3D[X];
    Point3DArray[0].y  = PL3DTop.P3Ds[i].P3D[Y];
    Point3DArray[0].z  = PL3DTop.P3Ds[i].P3D[Z];
    Point3DArray[1].x  = PL3DTop.P3Ds[i1].P3D[X];
    Point3DArray[1].y  = PL3DTop.P3Ds[i1].P3D[Y];
    Point3DArray[1].z  = PL3DTop.P3Ds[i1].P3D[Z];
    if(i==0)
    {
    j1 = lNumPoint-2;
    Point3DArray[2].x  = PL3DTop.P3Ds[j1].P3D[X];
    Point3DArray[2].y  = PL3DTop.P3Ds[j1].P3D[Y];
    Point3DArray[2].z  = PL3DTop.P3Ds[j1].P3D[Z];
    }
    else
    {
    j1 = i-1;
    Point3DArray[2].x  = PL3DTop.P3Ds[j1].P3D[X];
    Point3DArray[2].y  = PL3DTop.P3Ds[j1].P3D[Y];
    Point3DArray[2].z  = PL3DTop.P3Ds[j1].P3D[Z];
    }
    pt0 = Point3DArray[0];
    CoordAxis(Point3DArray, false, dAxisCos);
    Tranformation3DCoordinate(pt0, Point3DArray[2], dAxisCos, pt2);
    if(pt2.y<0)
    {
    Point3DArray.RemoveAll();
    return true;
    }
    }
    Point3DArray.RemoveAll();
    return false;
    }
      

  2.   

    多谢各位,判断凸多边形的算法我已经实现了,上周五客户就此问题已经认可,原来他所谓的GDI API,不过是在其中一处需满足与轴有两个两侧的交点时利用判断点是否在区域内的函数PtInRegion之类的API来判断