Comments (9)
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.
I feel this issue is addressed by the d3-bboxCollide plugin.
from d3-force.
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.
I’ve updated the README in 8b6cffa.
from d3-force.
That's much-needed, Mike! And would be great if it comes to real! 👍
from d3-force.
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.
@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.
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.
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)
- Saving, restoring and continuing a d3-force page HOT 6
- Iterative-Relaxation in d3.forceLink
- README has links to non-force-directed beeswarms
- Forcing angle in crystalline structure HOT 1
- simulation compute x/y/vx/vy as NAN sometimes HOT 1
- Collide force doesn't handle identical initial positions well HOT 7
- use in nuxt js
- Method to get all forces currently set (or at least clear them)
- Adding labels on top of nodes HOT 3
- Cannot assign to read only property 'vx' of object '#<Object>' HOT 1
- forceSimulation: number too small: cx="-3.2056569513393925e-168", Safari 15.4 HOT 2
- consider making .tick() reversable / accept negative iterations HOT 6
- All nodes starts to move when click and holding one node HOT 3
- Importing to NestJs causes module import error
- Cant pass extra data in nodes in simulation.nodes function HOT 1
- `forceCollide` ignores fixed positions HOT 5
- d3 v7 chained methods of forceLink "is not a fucntion" HOT 2
- `README` links to deprecated notebook HOT 1
- if you change a variable in an expression and use it twice gives undetermined result ( a = i++ + i;)
- Opportunity for performance gains via d3-force-reuse?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from d3-force.