title: How do I select a set of grid cells along a given angle quickly?
body: <p>I have set up a grid class that contains theoretical cells.</p>
  
  <p>I have a method <code>collectCells()</code> which accepts a starting point, radians and distance as arguments. I want this method to return an Array containing all the cells that are along a given angle and that are within the specified distance from the starting point, e.g.</p>
  
  <p><img src="https://i.stack.imgur.com/78KsQ.png" alt="enter image description here"></p>
  
  <p>The easiest way for me to do this is just loop through all the pixels in the given direction and pick cells up as I go, something like:</p>
  
  <pre><code>for(var i:int = 0; i&lt;distance; i++)
  {
      startPoint.x += Math.cos(radians);
      startPoint.y += Math.sin(radians);
  
      if( start point falls within uncollected cell) collect cell;
  }
  </code></pre>
  
  <p>This is obviously really poor, as the loop will be as long as the distance I specify - extremely slow.</p>
  
  <p>I tried something different, creating a <code>nextCell()</code> method which accepts the last collected cell and radians. The method threw a point 25 pixels in the direction specified by radians, collected the resulting cell and then started over from that cell for a given amount of cells.</p>
  
  <p>I didn't really think about this approach clearly enough, and once done realized that I had a problem, being that the actual path I'm testing gets broken each time the next cell is sought, e.g.</p>
  
  <p><img src="https://i.stack.imgur.com/QJitL.png" alt="enter image description here"></p>
  
  <p>Where the green dotted line is the desired path, and the blue lines are the paths that make up each <code>nextCell()</code> call because the check is made from the centre of each cell.</p>
  
  <p>What is the correct way to efficiently collect the cells in a given direction over a specified distance (pixels)?</p>