How can I aesthetically improve my percent light occlusion formula?

17 Views Asked by At

I was working with the following problem:

Given a sensor along the $x$-axis from the origin to $(l,0)$, a light source at $(x_1,y_1)$, and a wall between them with one corner at $(x_2,y_2)$ and the rest extending away at the angle $\theta$ for a distance of $r$. What percent of the sensor will be alit, or receiving light?

I ended up with two essential equations for solving the problem, the first finds the $x$ value of the point of intersection between the line connecting a point $(a,0)$ along the sensor and the line source and the line of the wall when its unbounded by $r$. This equation is $f(a)=\frac{ay_1+(a-x_1)(\tan(\theta)x_2-y_2)}{y_1+(a-x_1)\tan(\theta)}$.

The second function gives a binary answer to well a number $x$ is within the range occupied by the wall, specifically $[0,l]$. This function is $g(x)=\frac{1}{2}+\frac{1}{2}\operatorname{sgn}(x-x_2)\operatorname{sgn}(x_2+r\cos(\theta)-x)$.

I believe that the following integral should calculate the decimal percent of the sensor recieving light: $\int^l_0 \frac{1}{l} g(f(x))dx$. When I finally reached this solution it seemed obtuse, is there any way that I can "clean it up"?