Giter Site home page Giter Site logo

Comments (9)

Fil avatar Fil commented on April 28, 2024 5

I've been playing with this recently
http://bl.ocks.org/Fil/3f52274945a2be33a3f6bfd585ca949b

=> generic polygon detection is easily done with d3.polygonContains():
=> do a quadtree search before calling it, if you want to scale to thousands of points

from d3-force.

mbostock avatar mbostock commented on April 28, 2024 5

I feel this issue is addressed by the d3-bboxCollide plugin.

from d3-force.

mbostock avatar mbostock commented on April 28, 2024 3

Implementing a rectangular collision force is relatively straightforward. I wouldn’t overload d3.forceCollide by putting it there, but you could implement your own custom force to do it. Here’s an example in 3.x:

http://bl.ocks.org/mbostock/4055889

from d3-force.

mbostock avatar mbostock commented on April 28, 2024 3

I’ve updated the README in 8b6cffa.

from d3-force.

nesvet avatar nesvet commented on April 28, 2024

That's much-needed, Mike! And would be great if it comes to real! 👍

from d3-force.

gravitypersists avatar gravitypersists commented on April 28, 2024

I'm having trouble understanding how I am supposed to update nodes from within a callback. I'm assuming there's some async behavior in there.

see: https://tonicdev.com/579956eeedc3e41200aac566/579956eeedc3e41200aac567

from d3-force.

mbostock avatar mbostock commented on April 28, 2024

@gravitypersists Please read the documentation for simulation.tick, which says:

This method does not dispatch events; events are only dispatched by the internal timer when the simulation is started automatically upon creation or by calling simulation.restart.

So in your example your tick event listener is not invoked until after the result is displayed to the console (assuming that tonic even continues to execute your code).

If you want to fix a node’s y-position to zero, set node.fy = 0 and see the documentation for simulation.nodes. (Note that you don’t have to re-set simulation.nodes after setting node.fy; that’s typically only done when you add or remove nodes from the simulation, not when you modify nodes’ properties.)

If you want to apply a custom force for every tick of the simulation, register a custom force using simulation.force instead of listening for tick events. Unlike in v3, tick events in v4 are intended for rendering the simulation interactively, not for affecting the result of the simulation.

If you want further assistance, please use Stack Overflow tag d3.js or the d3-js Google group to ask for help. This issue is intended to be a discussion around collision detection, not debugging your code. Thank you for your understanding!

from d3-force.

gravitypersists avatar gravitypersists commented on April 28, 2024

Unlike in v3, tick events in v4 are intended for rendering the simulation interactively, not for affecting the result of the simulation.

I see. Sorry if this seemed off-topic, only in retrospect do I realize that. I was trying to implement a collide callback for rects similar to the issue at hand and made the faulty assumption that tick callbacks could affect the simulation just as force callbacks could, and was naively using the two interoperably. Thanks for your help, and apologies for asking in the wrong place.

So this is not all for nothing, do you think it's appropriate to mention this in the documentation a bit more clearly? I'd be happy to try and fit it in, but only if you suggest so.

from d3-force.

erichanson avatar erichanson commented on April 28, 2024

From what I can tell, d3-bboxCollide only detects bounding box collisions. d3.polygonContains only detects point collisions. Anybody found a generic polygon collision solution? That's what I believe this issue is asking for.

from d3-force.

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.