Code Monkey home page Code Monkey logo

Comments (5)

mbostock avatar mbostock commented on July 21, 2024 5

I’d recommend subtracting by 0.5 so that the average jitter is still zero, like this example:

var voronoi = d3.voronoi()
    .x(function(d) { return d.x + Math.random() - 0.5; })
    .y(function(d) { return d.y + Math.random() - 0.5; });

from d3-voronoi.

mbostock avatar mbostock commented on July 21, 2024

The problem is that your input is (approximately) collinear:

screen shot 2016-07-18 at 2 32 08 pm

Unfortunately, this Voronoi implementation doesn’t gracefully handle such input. As Jason wrote in d3/d3#1895 (comment),

This is a specific instance of a more general problem: there is more than one possible Delaunay triangulation for n ≥ 4 cocircular points; otherwise there is always a unique triangulation satisfying the Delaunay property. I think a reasonable fix is to pick an arbitrary Delaunay triangulation in this situtation.

Your input data exhibits a similar error here:

http://www.raymondhill.net/voronoi/rhill-voronoi.html

If you click “Clear all sites”, paste this in, and then click “Parse as sites”:

0.03638187704872731,464.2891731435667
18.726131781749977,447.97448002565795
79.47054617672242,394.9493467555858
126.61481653614429,353.7960778727167
178.5339693099149,308.4747092741625
197.96420712404677,291.51362799902915
266.8323214526062,231.39713866083747
343.10585755513114,164.81629403340833
421.6683900355436,96.23733420146249
497.7763624024437,29.80101379463332

You’ll see a TypeError: Cannot read property 'site' of undefined.

I probably won’t be able to fix this in the near future… Sorry. You can probably work around by adding a tiny amount of random jitter to your points (though that is no guarantee, in the extremely unlikely case your jittered input happens to still be collinear or cocircular).

Related d3/d3#235 d3/d3#1895 gorhill/Javascript-Voronoi#12.

from d3-voronoi.

m-rutter avatar m-rutter commented on July 21, 2024

Yeah, I thought it might be related to that existing issue as those sets of values are highly correlated. I'm building an interface in which I'm allowing users to plot different sets of values, including that rather uninteresting pair. It would be nice if it could fail gracefully so I could plot something else or render a message in its place. Right now the user has the potential to kill the browser window with an indefinite loop if they are an especially boring and/or unlucky individual :P

I would like to take the opportunity Mike to thank you for this library, and the continuing work and support you have put in including the countless examples and high quality tutorials. Taking the time to learn your library helped me get my first job as a developer, and so I'm personally very grateful.

from d3-voronoi.

mbostock avatar mbostock commented on July 21, 2024

Thank you. I expect that adding a tiny bit of random jitter would be safe if you don’t mind sacrificing accuracy.

from d3-voronoi.

m-rutter avatar m-rutter commented on July 21, 2024

Yep, adding jitter with Math.random() to the scaled value in the accessors is a good enough trade off for my (and I imagine the majority of) cases.

const voronoiGen = voronoi()
      .x(d => x(d.x) + Math.random())
      .y(d => y(d.y) + Math.random())
      .extent([[0, 0], [w, h]]);

from d3-voronoi.

Related Issues (20)

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.