Getting the angle between edges using Blender Geometry Nodes if several edges come out of a vertex

In the “Calculating the angle between edges using Blender Geometry Nodes” post, I was asked what to do in a more general case, when several edges come out of one vertex of the mesh? This problem can also be solved using Geometry Nodes, but the approach to the solution here is slightly different.

First, from the node tree that we already have, select the main part for calculating the angle by three points and wrap it in a node group (Ctrl + g). Name it “angle_by_3_points”.

The coordinates of the vectors of three points are fed to the input of our node group, and at the output we get the angle between them in degrees. Please note that the order of connecting the point coordinates to the group input sockets is important! The middle point (the one that is just the corner) must be connected to the middle socket of the group. Otherwise, the calculation result will be incorrect.

Now in the new scene, create some simple mesh, but with vertices that are adjacent to more than two edges.

Add the Geometry Nodes modifier to it and create the initial node tree.

Unlike the previous version, here we cannot start working from the point indices. We do not know the order of the edges adjacent to each specific vertex of the mesh, and therefore we cannot unambiguously determine the angle based only on the vertex.

We need to start from the corner. And here the Edges of Corners node will help us, which works in the Face Corner domain.

Add this node to the node tree (shift + a – Mesh – Topology – Edges of Corner). At the input, this node receives the face corner index, and at the output it gives the indices of two edges that actually form this corner.

Also add the Index node (shift + a – Geometry – Read – Index) and connect it to the input socket of the Edges of Corner node.

To monitor the results, add the Viewer node (shift + a – Output – Viewer) and open the Spreadsheet area. For both the node and the Spreadsheet, switch to working with the Face Corners domain to get the binding of the results as we need – to the corners of the polygons.

Now for each corner we have links to both edges that form it. It remains to switch from the edge indices to their coordinates.

To get the coordinates, as before, we will use the Position node. Add it to the node tree (shift + a – Geometry – Read – Position).

To get the coordinates by the edge indices, use the Evaluate at Index node. It returns the value of the input socket for the specified index. Add this node to the node tree (shift + a – Utilities – Field – Evaluate at Index).

Link the value from the Position node output socket with the Value socket, and the index value of one of the corner edges that we get from the Edges of Corners node output to the Index socket.

In order for the node to give us the correct result, we need to switch it to the Vector – Edges mode.

Now for each corner we have the coordinates of a point of one of the edges that form this corner.

Make a copy of the Evaluate at Index node (shift + d) and feed it the index of the second edge from the Edges of Corner node.

Now we have the coordinates of two points for two edges that form the corner.

It remains to find the coordinates of the central corner point.

And it’s very easy to get it. Again, using the Evaluate at Index node. Make another copy of this node (shift + d), but switch it to the Vector – Face Corner mode. We still feed Position to the Value input socket, and feed the index from the initial Index node to the index input.

In this case, we get the position of the corner by the index of the corner, which exactly corresponds to the coordinate of its corner point.

So, we got the coordinates for all three points for each corner of the mesh geometry. It remains to calculate the actual value of the corner.

Append to the scene (File – Append) and add (shift + a – Group + …) to the node tree the “angle_by_3_points” node group created at the very beginning. Feed the obtained coordinates to its input sockets (remember that it is important to maintain the correspondence of the coordinates to the sockets). And send the result from the output socket to the Viewer node.

Since in the 3D viewport, the corner attributes are superimposed on each other when displayed, the results are most conveniently viewed in the Spreadsheet area.

And here we see that for all angles the correct result is now calculated, regardless of how many edges come out from the vertex forming the angle.

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comment
Newest
Oldest Most Voted
Inline Feedbacks
View all comments