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

Incoherent result for 3 points #14

Open
chandon opened this issue Jun 24, 2019 · 0 comments
Open

Incoherent result for 3 points #14

chandon opened this issue Jun 24, 2019 · 0 comments

Comments

@chandon
Copy link

chandon commented Jun 24, 2019

I'm trying to compute with 3 points, i got incoherent result (with empty area and overlaping areas...)

image

I tried it with gorhill/Javascript-Voronoi, the result is OK

I tried to compare gorhill/Javascript-Voronoi vs this library (and implemented some fixes, like fully rewriting closeCells), but i don't see any real difference between the 2 libraries that explain the problem

    $voronoi=new \sroze\voronoi\Nurbs\Voronoi();

    $bbox = new \stdClass();
    $bbox->xl = 0;
    $bbox->xr = 360;
    $bbox->yt = 0;
    $bbox->yb = 360;

    $sitesList=[
        new \sroze\voronoi\Nurbs\Point(230.8672211,94.3521468),
        new \sroze\voronoi\Nurbs\Point(230.793264,94.310584),
        new \sroze\voronoi\Nurbs\Point(221.84149120083,102.55202538466)
    ];
        
    $diagram = $voronoi->compute($sitesList, $bbox);

    // TEMPORARY
    // Create image using GD
    $im = imagecreatetruecolor(360, 360);

    // Create colors
    $white = imagecolorallocate($im, 255, 255, 255);
    $red = imagecolorallocate($im, 255, 0, 0);
    $green = imagecolorallocate($im, 0, 100, 0);
    $black = imagecolorallocate($im, 0, 0, 0);

    // Fill white background
    imagefill($im, 0, 0, $white);
     
    // Draw points
    for ($i=0; $i < count($sitesList); $i++) {
        $point = $sitesList[$i];
          imagerectangle($im, $point->x - 2, $point->y - 2, $point->x + 2, $point->y + 2, $black);
    }

    // Draw polygons
    $j = 0;
    foreach ($diagram['cells'] as $cell) {
        {
        $points = array();
     
        if (count($cell->_halfedges) > 0) {
            $v = $cell->_halfedges[0]->getStartPoint();
            if ($v) {
                $points[] = $v->x;
                $points[] = $v->y;
            } else {
                var_dump($j.': no start point');
            }
     
            for ($i = 0; $i < count($cell->_halfedges); $i++) {
                $halfedge = $cell->_halfedges[$i];
                $edge = $halfedge->edge;
     
                if ($edge->va && $edge->vb) {
                    imageline($im, $edge->va->x, $edge->va->y, $edge->vb->x, $edge->vb->y, $red);
                }
     
                $v = $halfedge->getEndPoint();
                if ($v) {
                    $points[] = $v->x;
                    $points[] = $v->y;
                }
            }
        }
     
        // Create polygon with a random color
        $color = imagecolorallocatealpha($im, rand(0, 255), rand(0, 255), rand(0, 255), 50);
        imagefilledpolygon($im, $points, count($points) / 2, $color);
    }
        $j++;
    }
     
    // Display image
    header('Content-Type: image/png');
    imagepng($im);
    die;
@chandon chandon mentioned this issue Jun 24, 2019
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

1 participant