How to position UI elements based on their rotation

Hello developers! :wave:
I need a hint on how to place one ui element to another evenly based on rotation.

Let me show you what I mean:
I hope it's clear

And probably it's too

It is necessary that the upper parts of the elements form a smooth polyline (no protrusions)

Any help is appreciated. Guesses and thoughts are also very helpful, so feel free to write them down.
Thanks everyone! :hugs: