在 python 中使用 CGAL 将 voronoi 图裁剪为有界框

问题描述 投票:0回答:0

我正在使用 CGAL 和 python 绘制 Voronoi 图。当 voronoi 图被限制在一个盒子时,我想计算围绕特定站点的边集。

import numpy as np
from CGAL import CGAL_Kernel
from CGAL.CGAL_Voronoi_diagram_2 import Voronoi_diagram_2
from CGAL.CGAL_Triangulation_2 import Delaunay_triangulation_2

sites = np.array([[-3, 2], [-5, -3], [2,5], [0,5], [0,0]], dtype=float)
print("sites = ", sites,end="\n\n")
sites_cgal = [CGAL_Kernel.Point_2(x, y) for x, y in sites]
dt = Delaunay_triangulation_2()
dt.insert(sites_cgal)
vd = Voronoi_diagram_2(dt)

for f in vd.faces():
    e = f.halfedge()
    d = f.dual()
    print('site = ', d.point())
    s = [e.source().point().x(),e.source().point().y()] if e.has_source() else [None,None]
    t = [e.target().point().x(),e.target().point().y()] if e.has_target() else [None,None]
    print("edge : source = ",s,", target = ", t)
    while True:
        e = e.next()
        sn = [e.source().point().x(),e.source().point().y()] if e.has_source() else [None,None]
        tn = [e.target().point().x(),e.target().point().y()] if e.has_target() else [None,None]
        if [s,t] == [sn,tn]:
            break
        else:
            print("edge : source = ", sn,", target = ", tn)
    
    print("\n")

我已经编写了一个程序来计算逆时针方向特定站点周围的边缘,但是在无界边缘的情况下我无法计算它。 我需要裁剪具有无限源或目标的无边界边,然后找到它沿边界框穿过的边。

python cgal
© www.soinside.com 2019 - 2024. All rights reserved.