Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cropping voronoi diagram to a bounded box using CGAL in python #231

Open
Helios1002 opened this issue Mar 9, 2023 · 1 comment
Open

Comments

@Helios1002
Copy link

Helios1002 commented Mar 9, 2023

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?

@lrineau
Copy link
Member

lrineau commented Mar 14, 2023

Is this issue solved by commit 6239989?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants