| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 581 人关注过本帖
标题:help----求助!!!!!!!!!
只看楼主 加入收藏
litfish
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2007-12-1
收藏
 问题点数:0 回复次数:0 
help----求助!!!!!!!!!
我写了个程序,现在知道那地方有问题,但是不理解为什么会出错。具体如下:
void Delaunay::buildSuperTriangle()
{
    if (pnt.size() < 3) return;    // nothing to handle

    // Determine the bounding box.
    std::vector<PointF>::iterator pnt_it = pnt.begin();

    double xMin=0.0;
    double yMin=0.0;
    double xMax=0.0;
    double yMax=0.0;

    for (; pnt_it != pnt.end(); pnt_it++)
    {
        double x= (*pnt_it)[0];
        double y= (*pnt_it)[1];
        if(x<xMin)
            xMin=x;
        if(x>xMax)
            xMax=x;
        if(y<yMin)
            yMin=y;
        if(y>yMax)
            yMax=y;  
    }

    double dx = xMax - xMin;
    double dy = yMax - yMin;

    // Make the bounding box slightly bigger, just to feel safe.
    double ddx = dx * 0.01;
    double ddy = dy * 0.01;

    xMin -= ddx;
    xMax += ddx;
    dx += 2 * ddx;

    yMin -= ddy;
    yMax += ddy;
    dy += 2 * ddy;

    // Create a 'super triangle', encompassing all the vertices. We choose an equilateral triangle with horizontal base.
    // We could have made the 'super triangle' simply very big. However, the algorithm is quite sensitive to
    // rounding errors, so it's better to make the 'super triangle' just big enough, like we do here.
    vertex vSuper[3];


    vSuper[0] = vertex(xMin - dy * sqrt3 / 3.0, yMin);    // Simple highschool edge, believe me.
    vSuper[1] = vertex(xMax + dy * sqrt3 / 3.0, yMin);
    vSuper[2] = vertex((xMin + xMax) * 0.5, yMax + dx * sqrt3 * 0.5);
    
        
        triangle tri(vSuper);
        superTri=tri;
//        std::cout<<"OK!!!!!!!!"<<"center0="<<superTri.getCenter()[0]<<"\t"<<"center1="<<superTri.getCenter()[1]<<std::endl;
//        std::cout<<"OK!!!!!!!!"<<"supTri00="<<((superTri.vtex(0))->point())[0]<<"\t"<<"supTri01="<<((superTri.vtex(0))->point())[1]<<std::endl;
//        std::cout<<"OK!!!!!!!!"<<"supTri10="<<((superTri.vtex(1))->point())[0]<<"\t"<<"supTri11="<<((superTri.vtex(1))->point())[1]<<std::endl;
//        std::cout<<"OK!!!!!!!!"<<"supTri20="<<((superTri.vtex(2))->point())[0]<<"\t"<<"supTri21="<<((superTri.vtex(2))->point())[1]<<std::endl;
}
这个函数是建立一个大的三角形,得到的这个三角形包含我考虑的所有的点。
但是我调用这个函数以后,在另一个函数里面输出的时候,得到的是错误的结果,
void Delaunay::Triangulate()
{   
  std::cout<<"Begin to generate the Delaunay triangle mesh!\n";
  tri.clear();
  buildSuperTriangle();
//  std::cout<<"OK!!!!!!!!"<<"center0="<<superTri.getCenter()[0]<<"\t"<<"center1="<<superTri.getCenter()[1]<<std::endl;
  std::cout<<"OK!!!!!!!!" << "supTri00=" << (superTri.vtex(0))->GetX() << "\t"<<"supTri01=" << (superTri.vtex(0))->GetY()<<std::endl;
  std::cout<<"OK!!!!!!!!" << "supTri10=" << (superTri.vtex(1))->GetX() << "\t"<<"supTri11=" << (superTri.vtex(1))->GetY()<<std::endl;
  std::cout<<"OK!!!!!!!!" << "supTri20=" << (superTri.vtex(2))->GetX() << "\t"<<"supTri21=" << (superTri.vtex(2))->GetY()<<std::endl;
  tri.push_back(superTri);

输出的这个三角形的三个顶点的坐标只有第一个是正确的,后面两个错误,不知道为什么会出现这种情况,烦请高手解答一下。

程序的所有代码见附件!谢谢!

624.tar.gz (256.75 KB)
搜索更多相关主题的帖子: help 
2008-07-01 21:06
快速回复:help----求助!!!!!!!!!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018279 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved