Godot Volornoi Sweepline

by Sinowa

21

Godot-Sweepline-Volornoi

A Godot 4.X addon that generates and displays a volornoi diagram using Fortone's sweepline algorithm. This project is a fun hobby project and I welcome you to fork it! :)

Example Results

Image of diagram displayed through a shader Image of a diagram displayed through Polygon2D

Features

Operation

You can generate a volornoi diagram through code using this plugin.

See full documentation here.

See Example folder for runnable examples.

  • To call the volornoi algorithm:
var point_list : Array[Vector2] = [Vector2(1,1), Vector2(3,1), Vector2(3,3), Vector2(2,2), Vector2(1,3)]
var voronoi : VoronoiSweepline = VoronoiSweepline.new()
voronoi.generate( point_list, [0, 4, 0, 4 ])

VoronoiSweepline.generate parameters:

    • point_list - The list of seed points that the algorithm uses. Must be in a Array[ Vector2 ] format.
    • sizebox - The area that the algorithm is iterating over. [left wall, right wall, floor, ceiling]. They CANNOT be negative and all points must be inside of the diagram. They cannot be on the border or errors may occur.
       (0,0)--floor----+   
         |             |
     left wall     right wall
         |             |
         +---ceiling-(x,y)
    

To use Llyod's relaxation algorithm

voronoi.relax()

Notes

  • Errors with polygon generation occur if there are points too close together due to computer floating-point in precision.* To relax the diagram you have to generate the diagram first so there are cells to relax

Data Structures

Sweepline Algorithm

class VoronoiSweepline:
    func _init() -> void
    func generate(point_list : Array[Vector2], sizebox : Array) -> void
    func relax() -> void
    func process_cell_chunk( chunk : Array, start_idx : int, output_lst : Array[Vector2]) -> void
    func calc_centroid(pointlist : Array) -> Vector2

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

Acknowledgments

Version

2.2.0

Engine

4.2

Category

2D Tools

Download

Version2.2.0
Download

Support

If you need help or have questions about this plugin, please contact the author.

Contact Author