使用CGAL的凸包平面的方程可能错误

问题描述

我是计算几何的新手。这可能是一个幼稚的问题。我已使用CGAL查找一组点的凸包。然后,我使用CGAL网站here上给出的示例代码提取凸包平面。该程序如下所示。

#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
#include <CGAL/GMP/Gmpq_type.h>
#include <CGAL/Polyhedron_3.h>
#include <CGAL/convex_hull_3.h>
#include <CGAL/Side_of_triangle_mesh.h>
#include <CGAL/number_utils.h>
#include <iomanip>

typedef CGAL::Exact_predicates_exact_constructions_kernel Kernel;
typedef CGAL::Polyhedron_3<Kernel> Polyhedron_3;
typedef Kernel::Point_3 Point_3;
typedef Kernel::Plane_3 Plane_3;
typedef Kernel::Vector_3 Vector_3;
typedef CGAL::Side_of_triangle_mesh<Polyhedron_3,Kernel> Point_inside;

struct Plane_equation {
    template <class Facet>
    typename Facet::Plane_3 operator()( Facet& f) {
    typename Facet::Halfedge_handle h = f.halfedge();
    typedef typename Facet::Plane_3  Plane;
    return Plane( h->vertex()->point(),h->next()->vertex()->point(),h->next()->next()->vertex()->point());
    }
};

Point_3 create_point(std::string x,std::string y,std::string z) {
  Point_3 p;
  std::istringstream input(x + " " + y + " " + z);
  input >> p;
  return p;
}

int main() {
    std::vector<Point_3> points;
        points.push_back(create_point("-780692485006853753617237/10240000000000000000000000000","-1563546083667768699030143/2500000000000000000000000","0"));
        points.push_back(create_point("379213264894343110801237/10240000000000000000000000000","0"));
        points.push_back(create_point("-780692485006853753617237/10240000000000000000000000000","0","-379213264894343110801237/10240000000000000000000000000","3223865085330535926726143/2500000000000000000000000","-780692485006853753617237/10240000000000000000000000000"));
        points.push_back(create_point("379213264894343110801237/10240000000000000000000000000","379213264894343110801237/10240000000000000000000000000"));
        points.push_back(create_point("379213264894343110801237/10240000000000000000000000000","379213264894343110801237/10240000000000000000000000000"));
        points.push_back(create_point("-780692485006853753617237/10240000000000000000000000000","780692485006853753617237/10240000000000000000000000000","-780692485006853753617237/10240000000000000000000000000"));
        points.push_back(create_point("0","0"));
        
    Polyhedron_3 poly;
    CGAL::convex_hull_3(points.begin(),points.end(),poly);
    // CGAL::draw(poly);
    std::transform(poly.facets_begin(),poly.facets_end(),poly.planes_begin(),Plane_equation());
    CGAL::set_pretty_mode(std::cout);
    std::copy(poly.planes_begin(),poly.planes_end(),std::ostream_iterator<Plane_3>(std::cout,"\n"));

    Point_inside inside_tester(poly);
    CGAL::Bounded_side res = inside_tester(Point_3(0,0));
    if (res == CGAL::ON_BOUNDED_SIDE) {
      std::cout << "Origin is inside" << "\n";
    } else if (res == CGAL::ON_BOUNDARY) {
      std::cout << "Origin is on the boundary" << "\n";
    } else {
      std::cout << "Origin is outside the polyhedron" << "\n";
    }

    for (auto it = poly.planes_begin(); it != poly.planes_end(); ++it) {
      std::cout << "A = " << it->a().exact() << "\n";
      std::cout << "B = " << it->b().exact() << "\n";
      std::cout << "C = " << it->c().exact() << "\n";
      std::cout << "D = " << it->d().exact() << "\n";
      std::cout << "\n";
    }

    return EXIT_SUCCESS;
}

使用convex_hull_3生成凸包后,我尝试提取所有平面的平面方程。下面是该程序的输出

Plane_3(0,-4.19475e-09,7.08424e-05,-2.62348e-09)
Plane_3(-4.76816e-05,-3.63522e-09)
Plane_3(4.76788e-05,-7.08382e-05,-1.76567e-09)
Plane_3(-9.83085e-05,-7.49499e-09)
Plane_3(-0.00014607,8.6358e-09,0.00014607,-1.11363e-08)
Plane_3(9.83085e-05,-0.000146061,-3.64062e-09)
Plane_3(0.000146074,4.19475e-09,-0.000146074,-5.40933e-09)
Plane_3(0,-8.6358e-09,-7.08511e-05,-5.40099e-09)
Plane_3(-4.77552e-05,-3.64083e-09)
Plane_3(-2.31608e-05,-1.76577e-09)
Plane_3(4.77552e-05,-1.7685e-09)
Plane_3(2.31595e-05,-8.57654e-10)
Origin is inside
A = 0
B = -219925823194877128532786493609493825335102426169/52428800000000000000000000000000000000000000000000000000
C = 906783046340871373991245871626108775814746030891/12800000000000000000000000000000000000000000000000000
D = -343864159553760260821702206832186399183132849909762204558692676563012167/131072000000000000000000000000000000000000000000000000000000000000000000000000000

A = -1220648677481324419677714143344481488159947374891/25600000000000000000000000000000000000000000000000000
B = 0
C = 0
D = -952951249343224727578040741115129097199790308301319818242882753758596167/262144000000000000000000000000000000000000000000000000000000000000000000000000000

A = 4999480934017386895980017109227629957533970363431367/104857600000000000000000000000000000000000000000000000000
B = 0
C = -3713963431989014270739610303686932051911864640103367/52428800000000000000000000000000000000000000000000000000
D = -1895869487765753248495994462519358098874827535092392449815572846416028200979/1073741824000000000000000000000000000000000000000000000000000000000000000000000000000

A = -10308396833918147444194565967124294714798768363431367/104857600000000000000000000000000000000000000000000000000
B = 0
C = 0
D = -8047687940708342026893035469747920357861814098710951530122415210209637672979/1073741824000000000000000000000000000000000000000000000000000000000000000000000000000

A = -1869689824690300646434385556309825774908173982891/12800000000000000000000000000000000000000000000000000
B = 452764851132051796393052935016376879217993818169/52428800000000000000000000000000000000000000000000000000
C = 1869689824690300646434385556309825774908173982891/12800000000000000000000000000000000000000000000000000
D = -1459652795429499560461049209852394023543048968469784428121757724600692167/131072000000000000000000000000000000000000000000000000000000000000000000000000000

A = 10308396833918147444194565967124294714798768363431367/104857600000000000000000000000000000000000000000000000000
B = 0
C = -7657796757080339395998850185710029997144662640103367/52428800000000000000000000000000000000000000000000000000
D = -3909080819216610292966257636154114768379010997867208966773927801542028200979/1073741824000000000000000000000000000000000000000000000000000000000000000000000000000

A = 1531693889550933264984755205027731173569843147269541/10485760000000000000000000000000000000000000000000000000
B = 219925823194877128532786493609493825335102426169/52428800000000000000000000000000000000000000000000000000
C = -1531693889550933264984755205027731173569843147269541/10485760000000000000000000000000000000000000000000000000
D = -709011182760540911322636241675226035790615443402528424913924328539636167/131072000000000000000000000000000000000000000000000000000000000000000000000000000

A = 0
B = -452764851132051796393052935016376879217993818169/52428800000000000000000000000000000000000000000000000000
C = -742927224532668239932907228623111584523283547269541/10485760000000000000000000000000000000000000000000000000
D = -707918709809939897610498041142184898705751664465632699646023679792068167/131072000000000000000000000000000000000000000000000000000000000000000000000000000

A = -1222532404587072576861092389210725463247004638891/25600000000000000000000000000000000000000000000000000
B = 0
C = 1869689824690300646434385556309825774908173982891/12800000000000000000000000000000000000000000000000000
D = -954421860938486024795167813392498809224920480657508534678004510218164167/262144000000000000000000000000000000000000000000000000000000000000000000000000000

A = -592917415200418328304777599907736063469544686891/25600000000000000000000000000000000000000000000000000
B = 0
C = 906783046340871373991245871626108775814746030891/12800000000000000000000000000000000000000000000000000
D = -462886170276655067642955341169240700211713020629945581049164605825540167/262144000000000000000000000000000000000000000000000000000000000000000000000000000

A = 1222532404587072576861092389210725463247004638891/25600000000000000000000000000000000000000000000000000
B = 0
C = 0
D = -463600504582595797850104669957953262356310406147548315149844146861108167/262144000000000000000000000000000000000000000000000000000000000000000000000000000

A = 2428445929960641645499203498146234146289758916775367/104857600000000000000000000000000000000000000000000000000
B = 0
C = 0
D = -920898909719754197337687026347401189092620563028663434317768459371714728979/1073741824000000000000000000000000000000000000000000000000000000000000000000000000000

您会注意到这条线指出原点位于凸包内部。现在,如果原点位于凸包内部,则如果我通过检查0*a + 0*b + 0*c + d来检查相对于平面的原点侧,那么对于某些平面,输出应该为正,对于某些平面,输出应该为负。但是在这种情况下,所有平面的输出(基本上是d值)为负。我在这里做错什么事?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...