I think 'c_trace' is a faster solution. When the trace hits a surface the 'normal' variable is set to the normal of the hit surface. The angle you require is the arc-cosine of the dot-product of the normal and trace direction.