【问题标题】:Python CGAL cube has incorrect area and volumePython CGAL 立方体的面积和体积不正确
【发布时间】:2019-08-16 15:44:22
【问题描述】:

有一个示例显示了一种基于用户手册(https://doc.cgal.org/latest/Polyhedron/index.html#title9,第 3.7 节)中的 C++ 示例创建表示单位立方体 (https://github.com/cgal/cgal-swig-bindings/wiki/BindingsExamples#polyhedron_prog_cubepy) 的 CGAL Polyhedron_3 对象的方法:

from CGAL.CGAL_Polyhedron_3 import Polyhedron_3
from CGAL.CGAL_Polyhedron_3 import Polyhedron_3_Halfedge_handle
from CGAL.CGAL_Kernel import Point_3

def make_cube_3(P):
  # appends a cube of size [0,1]^3 to the polyhedron P.
  assert P.is_valid()
  h = P.make_tetrahedron(Point_3( 1, 0, 0),Point_3( 0, 0, 1),Point_3( 0, 0, 0),Point_3( 0, 1, 0))
  g = h.next().opposite().next()
  P.split_edge( h.next() )
  P.split_edge( g.next() )
  P.split_edge( g )
  h.next().vertex().set_point( Point_3( 1, 0, 1) )
  g.next().vertex().set_point( Point_3( 0, 1, 1) )
  g.opposite().vertex().set_point( Point_3( 1, 1, 0) )
  f = P.split_facet(g.next(),g.next().next().next())
  e = P.split_edge(f)
  e.vertex().set_point( Point_3( 1, 1, 1) )
  P.split_facet( e, f.next().next())
  assert P.is_valid()
  return h

P = Polyhedron_3()
h = make_cube_3(P)
assert not P.is_tetrahedron(h)

但是,当我尝试计算立方体的面积和体积时,这些值是正确值的一半:

from CGAL.CGAL_Polygon_mesh_processing import area, volume
print('Area:', area(P))
print('Volume:', volume(P))
>>> Area: 3.0
>>> Volume: 0.5

请说明原因。

【问题讨论】:

    标签: python geometry cgal


    【解决方案1】:

    这些函数需要对网格进行三角剖分。将代码更新为:

    from CGAL.CGAL_Polygon_mesh_processing import area, volume, triangulate_faces
    triangulate_faces(P)
    

    给出预期的结果。

    【讨论】:

      猜你喜欢
      • 2013-08-09
      • 1970-01-01
      • 1970-01-01
      • 2023-03-26
      • 2021-09-05
      • 1970-01-01
      • 1970-01-01
      • 2013-12-08
      • 2012-07-21
      相关资源
      最近更新 更多