Part Pos/Angle Help

Currently I am experimenting with some mathematical scripts and I’d come across a problem that I seemingly cannot solve.

I want to provide a similar behavior that the Archimedes plugin does; but I’m not sure how to approach doing/learning it. I’d tried many things such as using ratios to set the positions but it does not seem to work. I also think it might have something to do with trigonometry because a right angle is formed when positioned properly by the outline boxes.

If you do not know what the Archimedes plugin does, it basically clones the part and connects it and you can set an angle to easily make angled parts off each other.