0
$\begingroup$

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$.

Figure 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.

Figure 2

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

$\endgroup$
  • $\begingroup$ The width must be $\le 1$ but what is max height? Must part of the rectangle always be in the center square? $\endgroup$ – Jens May 5 '16 at 17:19
  • $\begingroup$ Yes. $Q$ is the vertical distance from the entry point to the bottom of cell 5 (upper boundary of cells 7, 8, 9), and $Q \in [0,1)$. The max height is given by point where the vector exits the cell 5. $\endgroup$ – Meecolm May 5 '16 at 17:53
  • $\begingroup$ I'm still confused. Does the rectangle not have some fixed width $W$ and some fixed height $H$? I saw the problem as randomly placing such a rectangle on your grid, with some part of the rectangle in the central cell, and then calculating how much of the rectangle's area was in each cell. $\endgroup$ – Jens May 5 '16 at 18:16
  • $\begingroup$ 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 $\pi/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. $\endgroup$ – Meecolm May 5 '16 at 18:26
  • $\begingroup$ Now it's clear. I suggest you add that description to your OP. $\endgroup$ – Jens May 5 '16 at 18:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.