The new NodeBox forum is live! Everything from support.nodebox.net moved here: sign in with the same email to pick up your old posts. Something not working? Write to forum-support@nodebox.net.

General DiscussionFrom the old forum

AI - Voronoi cells

1 reply Last reply

  1. Hi all,

    Here's are some first attempts on making a Voronoi diagram/tessellation subnode with the use of Claude. After some preliminary tests - 1 and 2 in the file - I gave it this prompt:

    Can you improve the Python 2.7 script of a Voronoi diagram triangulation script for use in Nodebox 3 based on example and the documentation provided? Don't use any external libraries. This script works quite well. But the contours are quite jagged though and not the straight lines you would expect from the polygons that voronoi cells typically would have. Don't change the arguments. And don't change the way the output (paths or geometry) is formulated.

    And below is its response. This (3) might be usable. In addition I asked it to add an argument for controlling the margins. Which it did, using percentages (4).

    I'll improve the Voronoi diagram triangulation script to produce cleaner, straighter contours while maintaining its compatibility with NodeBox 3. Let me analyze the current implementation and suggest enhancements.*
    
    Analysis of the Current Script
    
    The current script has a few limitations that lead to jagged contours:
    
        The create_simple_voronoi function uses a grid-based approach that approximates Voronoi cells rather than generating true Voronoi polygons with straight edges.
        The create_improved_voronoi function attempts to create proper Voronoi cells with straight edges but might have issues with numeric stability or edge cases.
        The boundary clipping could be more precise.
    
    Improved Implementation
    
    I'll focus on enhancing the script to produce cleaner, more geometrically accurate Voronoi cells with straight edges while keeping the same function arguments and output format.
    Improvements to the Voronoi Diagram Script
    
    I've improved the Voronoi diagram implementation while maintaining compatibility with NodeBox 3. The main enhancements focus on producing cleaner, straighter contours that better represent true Voronoi cells.
    Key Improvements:
    
        Better Point Distribution
            Implemented a Poisson-disk sampling approach to generate more evenly distributed seed points within the boundary
            Added minimum distance constraints between points to prevent numerical instability
        True Voronoi Cell Generation
            Completely rewrote the core algorithm to produce geometrically accurate Voronoi cells with straight edges
            Implemented proper half-plane intersection for cell computation
            Added polygon sorting to ensure vertices are in the correct order
        Improved Boundary Clipping
            Added a proper polygon-to-polygon clipping algorithm (Sutherland-Hodgman) to accurately clip Voronoi cells to the boundary
            Handles complex boundary shapes more effectively
        Robust Fallback Mechanism
            Created a more reliable fallback method using grid sampling and convex hulls
            The system will automatically switch to this if the primary algorithm fails
        Numerical Stability
            Added checks for degenerate cases and small numerical errors
            Better handling of edge cases for more reliable results
    
    Unchanged Elements:
    
        Function signatures remain the same to maintain compatibility
        Output format continues to be paths/geometry as before
        No external libraries are used
    
    The enhanced script should produce visually cleaner Voronoi diagrams with properly straight edges between cells while maintaining all the functionality of the original implementation.
    

    Let me know how this works and whether there are suggestions for improvements.

    Floris

    Copy link
  2. Floris,

    I FINALLY got around to really looking at this thing. My feedback:

    1. It's already very cool!

    2. Version 4 seems to work well and is obviously better than the first 3 attempts. I see no point in even looking at versions 1, 2, or 3. Let's only consider v4 moving forward.

    3. It uses a crude interpretation of the boundary shape. It ignores curves and treats the control points of a bezier curve as ordinary points. So if you give it a circle, it will treat that as an octagon. It also ignores contours. So if you give it a capital B it will use the outside of that shape (minus the curves) and ignore the two holes. The circle packing function was able to handle curves and contours, so I see no reason why this node could not do the same.

    4. It does not ask for a set of seed points. Instead it just creates its own seeds using a Poisson distribution. That is actually quite nice if all you want to do is generate a random Voronoi pattern. But I would also like the option of supplying my own list of points. This would make the node much more powerful and versatile, for both data visualization and for generative art.

    What do you think?

    Two asks for Claude:

    4a. Handle ANY boundary shape (including curves and contours).

    4b. Create an alternative version of 4a which asks for a point list instead of a cell count and uses that list instead of generating its own point list. I could then make a wrapper that would use the point list if the user supplies one (4b), or uses a cell count if they do not (4a).

    John

    Copy link

Know something that helps?

Sign in with your email address to reply. No password needed.

Sign in to reply