Wall orientation problem

I have a similar problem here from long back…!

I tried to create a script for it but dint work well with non rectangular room…!