I am an undergraduate student working on a large research project and one part involves calculating the portions of a rectangle that lie in different parts of a cartesian grid. In the figure below, I am trying to finding the portion of the grey rectangle that lies in each of the cells. Assume $\phi \in (0, \pi/2)$, and the width $W \le 1$, and $Q \in [0,1)$ (where $Q$ is the point at half the width $W/2$). While $\phi$ is given here as an angle, I am not using it as an angle because this is has to be coded and trig is expensive (it is given as such for easy descriptions in the paper I am working on). Instead I use the normal, $\vec n = [x, y]: \| \vec n \| = 1$.
I have been working on this for a while, and I have a solution using many cases about where the corners lie and trigonometry to find these areas. However, this seems inefficient in retrospect (for example the image below which is a figure to describe finding the area in cell 2 given certain conditions - only the upper half of the rectangle is displayed for simplicity). I was wondering if anybody else had any ideas of methods that would be more elegant.
A couple other notes: The length is the distance from the entry point to the exit point of the center cell. I have a calculator programmed to give that, so in solutions you can just address it as $L$. Let $W$ be the entire width of the rectangle.
Thanks in advance.
ADDITION: As addressed in the comments, the total area of the rectangle is $W \times L$. The ray is the at the center the of the rectangle with length $L$ and rectangles of area $LW/2$ on either side. Also, the middle-right cell is supposed to be cell 6; the centermost cell is cell 5.
The rectangle is developed by the following: Pick a point on the left hand boundary of the center cell. Now draw a line from that point given that the angle between the line and the $x$ axis is between 0 and $π/2$. Now where that line hits the boundary of the cell is where it stops. This is $L$. Now on either side on this line, there are 2 rectangles of size $LW/2$. I want the area of these rectangles that lies in each cell

