Just thought about it and tested it, you can replace the vec_to_angle code with rotation_tilt = -asinv(n.z); which gives you the very same angle as with your current code but more elegant and much faster.
"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual