How to get this angle?

283479-aa.png

hi guys:
i’m making a ruler and i want it automatically stick to a plane when it close enough, here’s my plan,
i set two linetraces one from top and one from bottom to hit the plane which to stick with, but i’m bad at geometry and don’t how how should i rotate the ruler with A B C D four points location known? please help me