Networks also known as graphs are a collection of objects where an object is related to different objects. That relation is often represented as a line between the objects or nodes. Graphs are really helpful to visually find highly connected nodes or population of similar nodes. In this quick tutorial, I will show you how to make a network with blender.
First, we are going to eliminate the starting cube and put the camera in a different location.
Nodes can have different locations, resulting in different visualizations for the same graph, the specific form in with the nodes are placed is known as the graph layout. In this post, I will exemplify how to implement the circular and the random layout. Feel free to use the one that you like the most.
As the name implies, in the circular layout all the nodes are placed in a circle. To obtain the cartesian coordinates of the circle we use the sine and cosine functions from the NumPy library. Then we add and rescale a sphere to the coordinates.
For the random layout, we use the random function from the NumPy library and generate a list of random locations. Then we iterate through the list adding the sphere to the location and rescaling it.
In both cases, the function used to add the nodes will return a list with the geometry names and a dictionary with its location. We are going to use that information to add the edges.
The relationship between the nodes can be represented in a matrix form, also known as incidence matrix, and as a list also known as incidence list. In this case, we are going to use the incidence list to add the edges.
From each element in the incidence list, we find the pair of nodes and calculate the midpoint between the nodes. At the midpoint, we add a new cube and rescale it, at the y-axis the scale is equal to the half distance between the points. And finally, the new cube is rotated to the angle formed between the points.
Now that we have all the geometries for the graph we are going to add the materials to each element. In this case, we are going to use the cycles render engine and nodes to specify the material for each element in the graph.
First, we add a new material and set the use of nodes as true. Then we add a new RGB input node, that will have the color of the current node, we connect the output of the RGB node to the Diffuse BSDF input, and we change the roughness to 1. Then we add a Glass BSDF node and set the roughness to 1. To mix the Glass BSDF and the Diffuse BSDF node we add a new Mix shader node and connect the output of the GlassBSDF and the Diffuse BSDF nodes to the input of the mix shader node. Finally, we connect the output of the mix shader to the inputs of the material output node.
For the edges of the graph, we follow a similar procedure, but instead of mixing two shaders, we only add an RGB node and a Principled BSDF node and connect those shaders accordingly.
With all the elements in the graph specified we can render the image and obtain the following.
Now you can display a graph with a circular or random layout using blender. The complete code of this tutorial can be found at my GitHub by clicking here. See you in the next one.