3D Force-Directed Graphs with Unity

They both use physics, it should be easy

Mathieu d'Aquin
Towards Data Science
6 min readNov 27, 2020

--

Word adjacency graph of common adjectives and nouns in “David Copperfield” (image by the author).

Displaying a graph or a network in a way that is not a complete mess can be hard. You want the most connected nodes to be close to each other, and to avoid edges crossing unnecessarily. The idea of the force-directed approach is that, instead of using a set of rules or a complex algorithm, a good layout for the graph is achieved by making every node act as if it was an object in an environment where simple physical properties apply: 1- Things that are connected attract each other, and 2- things that are close to each other push each other away. In that sense, the force-directed layout modules of popular graph visualisation frameworks such as D3.js are small, specialised physics engine.

That’s all very good. However, for large, highly connected graphs, having only two dimensions for the objects to move around might not be enough. There is also little scope for navigation: You either see the whole graph, which might tell you nothing, or you only see a small piece which might be too limited. So a 3D version of force-directed graph visualisation might be helpful. It might be a bit of a pain to implement though. A nice looking rendering of the nodes and edges in 3D would be bad enough. Having, on top of that, to manage efficiently all the multiple forces that apply on all the nodes dynamically…

--

--

I’m a developer and a researcher in data science, knowledge engineering and artificial intelligence. I’m a (some would say grumpy) frenchman writing in english.