# Instance alignment on corners while maintaining right angles

I'm trying to align corner pieces so they always face inwards and also maintain right angles, like so:

By aligning instances to vertex normals I'm getting something like this (red face is always pointing inwards, so it's doing something right): Current nodetree:

Earlier I tried to rotate or mirror instances by selecting them manually via vertex IDs, but that's tedious and not at all dynamic.

So the question is: what kind of vector math magic can I use to get the result in the first picture? Can it be done with vertex normals, or perhaps by somehow referencing neighboring points to get the orientation?

PS: another question that was suggested while composing this one (How to properly orient instances along corner edges) didn't help very much.

Edit: typos

Edit 2: Temporary solution

I was able to scale (mirror) instances depending on their position in relation to bounding box center (if it's below, mirror along Z axis etc.):

That did the trick, but sadly it only works with simple boxes. Or you'll get something like this where mid-level corner pieces are incorrectly pointing upwards as they are below the bounging box center (this problem also applies to X and Y axis):

Here's a way for all corners (except ambiguous).

Since the base mesh has a simple structure (Edges are aligned to X, Y or Z axis, normals and edge angles don't vary very much, except for the sign), the normals of the vertex and edge angles of connected edges can be used to determine if a vertex will get an instance or if it needs additional rotation.

If edges with angles equal to $$0$$ are ignored, determining if a corner is concave or 'semi-concave' is much easier (especially if there is inset faces). They can be ignored by transferring captured edge angles (captured to edges) from a mesh with edges of angle $$0$$ deleted:

Here's some values and what they mean here:

• If the vertex has a number of edges equal to 3 (ignoring edges with angle $$0$$), it is a three-point corner. 

• 'Semi-Convex' corners (with one concave edge) have an average edge angle of $$\large -\frac{\pi}{6}$$. 

• Fully concave corners will have an average edge angle equal to $$\large -\frac{\pi}{2}$$. 

• Ambiguous corners (concavity of surrounding edges equals convexity) have an average edge angle of $$0$$, this is also true for non corner points (surrounding faces face same direction). Instances weren't put here. 

• 'Semi-Concave' corners (with one concave edge) have an average edge angle of $$\large\frac{\pi}{6}$$. 

• Fully convex corners have an average edge angle equal to $$\large\frac{\pi}{2}$$.

We can use these to do specific things depending on the properties of the corner.

Geometry Nodes:

Here only convex corners are selected:

You could put a different instance on ambiguous corners by checking the edge angle and using the result as instance index:

• +1. Missed this one earlier. Really nicely done. Commented Jul 11, 2022 at 7:36
• Sorry for the long wait! I was honestly hoping to dissect your solution to get some understanding of how exactly it works and only then reply, but then life happened. I did not have a chance to dive into it, so I'll just mark it as a solution. All I can say is that it just works, and thank you dearly for your time! Commented Sep 2, 2022 at 19:16

In the end, I did it with face normals by using three compare nodes and three switches. Compare nodes look if normal points in certain direction (positive X, negative Y, negative Z) and switches pass the corresponding scale value down the line where it gets added together and plugged into instancer's scale input:

Result:

All thanks to this guy Kammerbild on YT: "Blender: procedural buildings with geometry nodes fields | pt. 2"

• How are you selecting convex v concave corners? Commented Jun 13, 2022 at 10:50
• @RobinBetts, if I understood correctly, you're referring to the fact that some vertices don't have corner pieces on them. I've somewhat cheated by using Vertex Neighbors and Math Less Than 4 nodes and plugged them into instancer's selection input. So any vertex that has 3 or less neighbors gets selected (you can see that in a nodetree screenshot in original post). Commented Jun 13, 2022 at 11:25
• Thx, sorry, missed it. :) Commented Jun 13, 2022 at 12:46