Question

I have stumbled across an implementation of Fortunes algorithm for a Voronoi diagram solver which works but I am unsure what is actually happening in the __construct method of the Edge class posted below (some snippets removed for clarity).

class Edge
{
    //removed member vars

    function __construct($start, $left_site_event, $right_site_event)
    {
        //removed property assignment
        //this->start = $start //etc etc

        $this->f = ($right_site_event->position->x - $left_site_event->position->x) / ($left_site_event->position->y - $right_site_event->position->y);
        $this->g = $start->y - $this->f * $start->x;

        $this->direction = new Vector(($right_site_event->position->y - $left_site_event->position->y), ($right_site_event->position->x - $left_site_event->position->x));
    }
};

The three lines i'm interested in comprehending are the assignment of the f, g and direction based on the position of both the left and right site events.

For a start, the f and g variables seem poorly named unless these adhere to some kind of formulaic nomenclature? What do these appertain to and what is actually calculated/determined here?

The direction would seem to me that it indicates the slope of the edge between both the left and right site events. Again, what is calculated here?

Any help in understanding this would be appreciated as it appears that the implementation I have found seems to flake out when two site events lie on the same y axis (i.e.: both the left and right site event y coordinates are the same).

Update

I have added a screenshot of the current results from my implementation ported from the source I found (see below). Also, if it is of any help to anyone, you can grab the latest (not quite working) copy of the solver from github.

Voronoi Solver

Was it helpful?

Solution

It looks a lot like f & g are meant to be calculating the slope & intercept of a straight line through the points, but the author mucked it up. If you'll allow me to abuse notation, f is defined as a ratio of an x coordinate value to a y coordinate value, which I'll write as f ~ x/y. Which means that in the definition of g, you're subtracting a f*x ~ x^2 / y term from a y term.

Now if f were actually meant to be defined as f ~ y/x, then in g's definition you'd be subtracting a f*x ~ y term from a y term, which would make much more sense. I also think the author might have accidentally lost a -1 in the definition of f (which is why the denominator is the opposite way round from the numerator), but I can't say for sure without seeing the rest of the code.

Also when the y-coordinates of the left and right site are the same, you get a division by zero in the definition of f which is probably why it's mucking up.

If you could explain what the start point represents, and whether the algorithm is sweeping from the left or the right, I might be able to figure out exactly what it's trying to do.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top