Giter Club home page Giter Club logo

voronoidiagram's Introduction

Voronoi Diagram

Fortune's Algorithm

  • This code has some double precision issues.
  • Only 150 lines.
  • This code uses splay tree. Worst time complexty is O(n log n).
  • Calculating the Voronoi Diagram with 1 million(1,000,000) random points in 2 seconds (single core, Intel(R) Core(TM) i9-9900K CPU @ 3.60GHz).
  • Code

Voronoi Diagram

Special thanks to

https://jacquesh.github.io/post/fortunes-algorithm/

build

sh build.sh

run

./A input.txt

input file format

n : # of points

(n)
(x1) (y1)
(x2) (y2)
...
(xn) (yn)

constraint

  • point must be distinct.
  • n != 0

function format

Reading main.cpp rendering part can be helpful to know about function format.

  • std::vector<pdd> input
    • Inputs. Order can (and will) be changed, so user should pay attention about this.
    • Additionally, input will sorted by (y, x) order.
  • std::vector<pdd> vertex
    • Vertex is locations of Voronoi Diagram's intersection points. It can contain same points, and the degree of each point is 3.
    • This code doesn't compress same points. If you want, then you should implement it.
  • std::vector<pii> edge
    • for(pii c : edge), Voronoi Diagram contains line from vertex[c.first] to vertex[c.second].
    • Voronoi can contain rays or straight line. In this case, rays are depicted as {-1, (point index)} or {(point index), -1}, and straight line are depicted as {-1, -1}. A direction of each line can calculate using area array.
  • std::vector<pii> area
    • Let (a, b) := i-th element of array area, and (u, v) := i-th element of array edge.
    • Then, Point input[a] is located CCW of an u->v line (or ray, or straight line), and point input[b] is located CW of an u->v line.
    • u->v line is a subset of perpendicular bisector of line segment from input[a] to input[b].
    • Straight line {a, b}, {-1, -1} through midpoint of input[a] and input[b].

GUI

  • Mouse whill operates to change scale.
  • Mouse drag operates to move screen.

And..

Feel free to ask questions.

And sorry for my poor English.

voronoidiagram's People

Contributors

zigui-ps avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

voronoidiagram's Issues

Question about VoronoiDiagram

Hello, zigui !
I am a new learner to computational geometry from China and I am trying to realize of VoronoiDiagram in C++.
I was quite interested at the first time when I found your code because you just coded with 150 lines and used splay tree instead of AVL. But I had a bit confused about some details of your code. Here are my question:
(1) the underlying principle of function line_intersection(a, b, u, v) in VoronoiDiagram.cpp : Is this function used to calculate the intersection point of two line (one is defined by point a and point b while the other is defined by point u and point v) ? I tested line_intersection({1,0}, {0,1}, {0,0}, {1,1}) and got a result point{1,1}. It obvious that the intersection should be {0.5,0.5}. Could you please explain the meaning of each argument and the principle of this function ?
(2) the principle of dealing with the false alarm in Fortune 's algorithm : As mentioned in the original Fortune 's algorithm, it exists 2 situation of false alarm. But I couldn't find the obvious dealing process of these false alarms in your code. I guessed you dealt with them in function get_event() with two if-return lines, but I couldn't understand these two lines well. By the way, I am not sure whether my supposal is correct . Could you please tell me how and where you deal with these false alarms ?
(3) the meaning of "end" field of node structure : I couldn't understand the end field here and why it is set as "size of edge * 2". Could you please explain it specifically ?

Thank you!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.