-
Notifications
You must be signed in to change notification settings - Fork 377
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
Consider adding a mass property to nodes #96
Comments
This great third party module implements what you describe https://github.com/vasturiano/d3-force-bounce |
Thanks. That seems to implement it for an alternative version of forceCollide, but I really want to use it with the other built-in forces like the many-body force, the link force and the center force. The many-body force will be the one that takes most effort to rewrite. |
Perhaps @vasturiano would have some ideas on how to approach integration with other forces. I'm not familiar enough with the work to advise as to whether that's possible or how to do it. |
I think that all you need to do to add a mass that mimics physics is just to replace all instances of |
There's also the API considerations. Have you tried implementing it in d3-force? Any PR in the works? |
Hey there, Just for reference it is doable to have Here's an example of them coexisting: |
You may also want to have a look at https://github.com/vasturiano/d3-force-magnetic. This is a variant of manyBody that mimics natural attraction/repulsion forces. Possibly, the |
I had a think about the API and am not sure how best it would be implemented. The simplest thing I can think of would be to have a property I did think about being able to set the mass separately for different forces as this would fit in better with the existing API. However I don't think this makes so much sense from a physics point of view. Here is a little digression to explain why I think respecting the physics is important. In the built-in force link force, there is a Although this is slightly off-topic, it would be useful (and a very easy backwards-compatible change to make) if you could set the |
@benstevens48 I see what you're saying, and I agree. Ideally, we would have a framework level And thanks for the interesting discussion! |
Hi @vasturiano , thanks for your reply. Allowing the user to provide a function (or constant) for the bias would be quite useful I think (independent of the mass issue). It's not quite equivalent to having a mass - you'd need to adjust the strength as well as the bias to get something equivalent. Also, for the many body force, adjusting the strength is not equivalent to having a mass. For example, setting a low strength on a node will decrease it's acceleration (like a large mass), but it will also decrease the amount it attracts/repels other nodes, which you might not want (e.g. you might want a very massive node which is also very repulsive). So, in conclusion, I think it would definitely by worth exposing bias as an accessor function, and this would be quite easy to implement. In addition, having a framework-level mass property would be highly desirable. |
@benstevens48 setting a low strength will actually not decrease the node's acceleration, in fact it will have no effect at all in its own acceleration. This is by design and boils down from Newton's 2nd law, obvious example being two objects on earth fall with the same constant acceleration regardless of their mass. Regarding |
@vasturiano , ah, I see, I thought that since the many body force could be both repulsive and attractive it was calculated according to Coulomb's law which uses the products of the two charges (strengths), but now I see that it's actually more like gravity or 'repulsive' gravity, with the strength being the mass (which cancels out because you first multiply by it to get the force then divide by it to get the acceleration, hence it doesn't appear). Having a Coulomb's law force with a mass as well would be slightly more flexible, although I will have to experiment with what works best for my scenario. |
Correction - I guess you can't achieve attraction between all the nodes with a Coulomb's law force so it would be a genuinely different force. |
You bring up an interesting point with Coulomb. I alluded to this on forceMagnetic (4th paragraph) but it wasn't resolved, possibly because it wasn't an issue for that use case. |
No, scrap that, equal signs repel each other. Sounds like we're talking about an entirely new force. Perhaps it could be just a new property/method option of |
This can cause weird effects when combining with other forces. I've spent way too much time tracking down why a part of a graph that looked like this
was floating up. I had a custom force that pulled This forced me to ship a customized version of the link force which simply has the bias removed.
This would be perfect 👍 |
Related to #128 |
PS: It would be useful to share the problematic graph as a block or observable notebook. |
Allowing nodes to have a mass property would be quite useful (so then the acceleration a produced by a force F acting on a node of mass m would be given by a = F/m, and this would also be used in calculating the centering force). For example, there might be a some nodes in your network (that may be quite important nodes for something) that you don't want to move around too much and stay quite central (but you don't want to fix completely), and giving them a large mass would achieve this. This can't be achieved by giving them a small charge since then they would no longer repel other nodes as strongly.
The text was updated successfully, but these errors were encountered: