【问题标题】:cgal python intersection - trying to return a polygon more complex than a trianglecgal python intersection - 尝试返回比三角形更复杂的多边形
【发布时间】:2020-03-28 13:27:49
【问题描述】:

我想使两个形状相交,返回两者之间的重叠。这必须包括重叠是非常复杂的形状(即不仅仅是三角形)。最终我想在 3D 中执行此操作,但即使我将其简化为 2D,我也遇到了同样的问题,因为它与任何基本的“is_foo”模板功能都不匹配,所以我无法恢复结果形状为了 CGAL::对象。

代码如下。注意使用的两个三角形应该返回一个不规则的四边形 ((0.75, 0.0), (0.25, 0.0), (0.0, 1.0), (0.8, 0.2))

from CGAL.CGAL_Kernel import Point_2
from CGAL.CGAL_Kernel import Triangle_2
import CGAL.CGAL_Kernel as CGAL_Kernel

tri1=Triangle_2( *[Point_2(*acoord) for acoord in [[0,0],[1,0],[0,1]] ] )
tri2=Triangle_2( *[Point_2(*acoord) for acoord in [[1,1],[0.5,-1],[0,1]] ] ) 

intersection=CGAL_Kernel.intersection(tri1,tri2)

print(intersection.empty()) ### FALSE
print(intersection.is_Point_2()) ### FALSE
print(intersection.is_Triangle_2()) ### FALSE
print(intersection.is_Segment_2()) ### FALSE
print(intersection.is_Line_2()) ### FALSE
print(intersection.is_Ray_2()) ### FALSE

有没有办法得到我不理解的四边形?我是以错误的方式接近这个吗?提前致谢

【问题讨论】:

  • 不可能,但我在this commit中添加了它。
  • 非常感谢!可能需要。在 3d 中也有相同交叉点的多边形 3?
  • 我错过了您需要 3D 的事实。需要一个类似的补丁......

标签: python intersection cgal


【解决方案1】:

查看the documentation for intersections。你的交集实际上是一个 std::vector。在 c++ 中,您可以使用

if (const std::vector<Point_2>* res = boost::get<std::vector<Point_2> > 
(&*result)) {
  std::cout << res.size() << std::endl;
}

但在 python 中,我认为你不能,在当前可用的版本中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-07-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-10
    • 2019-08-12
    相关资源
    最近更新 更多