cropping voronoi diagram to a bounded box using CGAL in python
Helios1002 opened this issue · 1 comments
I'm using CGAL with python to draw Voronoi diagram. I would like to compute the set of edges that surround a particular site when the voronoi diagram is restricted to a box.
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")
I have written a program to compute the bounded edges around a particular site in anti-clockwise direction but I am unable to compute it in case of unbounded edges. In case of unbounded edges since souce or target is in infinity, to prevent the kernel from crashing I have printed them as None
I need to clip the unbounded edges that has source or target in infinity and then find the edges that it traverses along the bounding box for every site. Aside from source and target, I'd also like to know whether there are any additional elements that may be used to transform the unbounded edge case into a ray, segment, or something else.
I'd also like to know if cropping the voronoi diagram would be possible using the function from CGAL.CGAL_Voronoi_diagram_2 import crop_voronoi_edge
. If so, how?