-
Notifications
You must be signed in to change notification settings - Fork 3
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
Constraining nodes to a sphere #6
Comments
Here's my suggestion: Graph.d3Force("radius", forceRadius(gData.nodes, 300));
function forceRadius(nodes, R = 1) {
return () => {
for (const n of nodes) {
const r = Math.hypot(n.x, n.y, n.z);
const u = Math.pow(r ? Math.sqrt(R / r) : 1, 0.05);
n.x *= u;
n.y *= u;
n.z *= u;
}
}
} |
Thanks @Fil, that looks great! The only unusual thing is that dragging a node seems to remove the force. Do you know why that is? And can you see an obvious way to keep the force applied while dragging? |
Dragging does not remove the force, but it pushes alpha up (the "temperature", if you will), making all the other forces stronger. You could change the parameter 0.05 to make it stronger with alpha if you wanted, but it would make the initial convergence less smooth. |
I really like this approach! Thanks for sharing. Thanks! |
I'm trying to constrain some nodes in 3D to a sphere. I'm using 3d-force-graph and hoping to do the constraining with d3-force-limit.
My current naive approach is here: https://codepen.io/jokroese/pen/ExQMrpj.
The problems are:
Do you have suggestions on next steps for moving forward with this?
Possible options:
The text was updated successfully, but these errors were encountered: