Basically I have two 2D points and there is a line between them. A cube is placed on the midpoint of this line. I want the cube to rotate so it is facing upwards from the line as the diagram below indicates.

I’ve been thinking through how I can do this using trig and I still haven’t come up with anything. Any ideas would be much appreciated 🙂
In pseudo-code: