【问题标题】:Bug in locate function?定位功能中的错误?
【发布时间】:2013-10-22 02:56:36
【问题描述】:

我是 CGAL 的新手,当我使用 .locate() 函数定位时 三角形中的一个点,有一些问题。 首先,我用三点 (-1,0) (1,0) (0,1) 构建一个三角形, 然后我用三角形检查一些点的相对位置, 要点是:

p0(0.8, 0.1) ---- locate in the triangle;
p1(0.95, 0) ---- locate on the edge (-1,0) ---- (1,0);
p2(0.8, 0.2) ---- locate on the edge (1,0) ---- (0,1);
p3(0.6, 0.4) ---- locate on the edge (1,0) ---- (0,1);
p4(0.7,0.3) ---- locate on the edge (1,0) ---- (0,1);

但是定位结果是:

p0 ---- FACE, right!
p1 ---- EDGE, right!
p2 ---- OUTSIDE_CONVEX_HULL, wrong!
p3 ---- EDGE, right!
p4 ---- FACE, wrong!

而点 p2, p3, p4 位于同一边 (1,0) ---- (0,1)

问题的原因是什么?

代码:

typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Delaunay_triangulation_2<K> Delaunay_triangulation;

void main()
{
    //generate the triangles
    std::vector<Point2> pts;
    pts.push_back(Point2(1,0));
    pts.push_back(Point2(-1,0));
    pts.push_back(Point2(0,1));
    Delaunay_triangulation dt;
    dt.insert(pts.begin(), pts.end());

    //locate point in the triangle
    Point2 pt0 = Point2(0.8, 0.1);//the point located in the triangle.(on the FACE ?)
    Point2 pt1 = Point2(0.95, 0);//the point located on the segment ( (1,0) ---- (-1,0) ) (on the EDGE ?)
    Point2 pt2 = Point2(0.8, 0.2);//the point locate on the segment ( (1,0) ---- (0,1) ) (on the EDGE ?)
    Point2 pt3 = Point2(0.6, 0.4);//the point locate on the segment ( (1,0) ---- (0,1) ) (on the EDGE ?)
    Point2 pt4 = Point2(0.7,0.3);//the point locate on the segment ( (1,0) --- (0,1) ) (on the EDGE ?)
    Face_handle fh0, fh1, fh2, fh3, fh4;
    Delaunay_triangulation::Locate_type lt0, lt1, lt2, lt3, lt4;
    int li;
    fh0 = dt.locate(pt0, lt0, li);//for pt0, lt0 is equal to FACE, right!
    fh1 = dt.locate(pt1, lt1, li);//for pt1, lt1 is equal to EDGE, right!
    fh2 = dt.locate(pt2, lt2, li);//for pt2, lt2 is equal to OUTSIDE_CONVEX_HULL, I think it's wrong!
    fh3 = dt.locate(pt3, lt3, li);//for pt3, lt3 is equal to EDGE, right!
    fh4 = dt.locate(pt4, lt4, li);//for pt4, lt3 is equal to FACE, I thing it's wrong!
}

【问题讨论】:

    标签: triangulation cgal locate


    【解决方案1】:

    浮点数不能代表所有可以写的十进制数。存在舍入误差。因此,这些点的坐标并不是您想的那样。采取以下程序:

    #include <iostream>
    #include <CGAL/Point_2.h>
    #include <CGAL/Simple_cartesian.h>
    
    typedef CGAL::Simple_cartesian<double> Kernel;
    typedef Kernel::Point_2 Point;
    
    int main()
    {
      std::cout.precision(17);
      Point p0(0.8, 0.1);
      Point p1(0.95, 0);
      Point p2(0.8, 0.2);
      Point p3(0.6, 0.4);
      Point p4(0.7,0.3);
      std::cout << p0 << std::endl;
      std::cout << p1 << std::endl;
      std::cout << p2 << std::endl;
      std::cout << p3 << std::endl;
      std::cout << p4 << std::endl;
      return 0;
    }
    

    显示点的坐标,精度高。输出如下:

    0.80000000000000004 0.10000000000000001
    0.94999999999999996 0
    0.80000000000000004 0.20000000000000001
    0.59999999999999998 0.40000000000000002
    0.69999999999999996 0.29999999999999999
    

    这些坐标解释了locate() 返回的所有位置。

    【讨论】:

    • 感谢您的帮助!
    猜你喜欢
    • 1970-01-01
    • 2018-05-09
    • 1970-01-01
    • 2016-09-16
    • 1970-01-01
    • 1970-01-01
    • 2022-01-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多