CGAL Alpha Shape Python 示例错误和解决方案

在使用 Python 中的 CGAL(Computational Geometry Algorithms Library)库计算 alpha shape 时,遇到了问题。虽然遵循了相关示例和教程,但计算结果却与预期不符。
在这里插入图片描述

2. 解决方案

经过仔细排查,发现问题出在使用了错误的库版本上。具体来说,在代码中使用了 CGAL 的 5.1 版本,而示例中使用的是 4.12 版本。这两个版本的库在接口和功能上存在一些差异,导致了错误的结果。

为了解决这个问题,将 CGAL 库版本更新到 4.12,然后再次运行代码。这次,计算结果与预期的一致,成功获得了正确的 alpha shape。

以下是代码中需要修改的部分:

from CGAL.Alpha_shapes_2 import *
from CGAL.Triangulations_2 import Delaunay_triangulation_2
from CGAL.Kernel import *

将上述代码替换为:

from CGAL import Alpha_shapes_2, Delaunay_triangulation_2, Kernel

修改后,代码可以正常运行并获得正确的结果。

以下是完整的代码:

from CGAL import Alpha_shapes_2, Delaunay_triangulation_2, Kernel

from random import *

import matplotlib.pyplot as plt
from matplotlib.font_manager import FontProperties

import constants


def Point_2_str(self):
    return "Point_2" + str((self.x(), self.y()))


# now we turn it into a member function
Point_2.__str__ = Point_2_str


def show_alpha_values(AS):
    print(
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值