I have the following situation

I want the angle the the nearest x and y vector (within 45 degrees) of the lines shown. What would be the best way to get his? I have marked up the angles I am looking for on the most onerous conditions to show what it is I am trying to do.