Newsgroups: comp.robotics
Path: brunix!cat.cis.Brown.EDU!agate!howland.reston.ans.net!europa.eng.gtefsd.com!newsxfer.itd.umich.edu!uunet!timbuk.cray.com!driftwood.cray.com!kilian
From: kilian@cray.com (Alan Kilian)
Subject: RE: Occupancy Question.
Message-ID: <1994Aug3.151857.25888@driftwood.cray.com>
Lines: 68
Nntp-Posting-Host: poplar010
Organization: Cray Research, Inc.
Date: 3 Aug 94 15:18:57 CDT

> How can I tell which grid locations are partially covered by any
> arbitrary rectangle lying on the grid?

You cannot solve this problem because its impossible.

Any arbitary rectangle can cover any grid cells and you can't tell which.

For example: An infinitely long rectangle will cover an infinite number
of cells.

Also a rectangle with negative width in one or more dimentions will cover
a negative number of cells. Or will it?

How about a rectangle so small that it can be placed exactly on a grid
boundary. Is it on none, one or both cells? Remember that computer
arithmatic only has so much precision.



The point of all this is that you didn't really ask a question.
If you start to define the problem in a precise way, you will 
be much further along to getting the answer yourself.

I'll help you get started:

If I define a rectangle as a length along the direction X and another
length along a direction Y where the X and Y directions are perpendicular.

Then I orient the rectangle by saying that the rectangle's X direction
is at an angle A in radians where zero radians points in the direction
of the positive X direction and PI/2 radians points in the direction
of the positive Y direction.

Then I state where the rectangle is located by specifying the X and Y
locations of the center of the rectangle as Lx and Ly.

Now you can get somewhere.

1) Where are the locations of the four corners of the rectangle?
   You will need to use sin(A) and cos(A) and multiply by the X and Y
   lengths and then add and subtract from Lx and Ly to get the 4 corners.

2) Now you need to state how big a cell is. Maybe you should have a cell
   be one unit in X and one unit in Y and located do that the center of
   the cell is at X+0.5 and Y+0.5

3) Then you can just take the four corners you calculated in #1 above
   and convert them from real numbers into integers and you have computed
   which cells the 4 corners are in. Note that the corners could be in
   1,2 or 4 different cells.

Can you write an algorithm to do this part?

When you have that, you can contact us again and we'll continue.



Interesting problem. Not nearly as trivial as it might first seem.
In fact I don't really know the general solution. I'll have to figure
it out if you really press me for the answer.


     -Alan "There aint no such thing as a free lunch" Kilian

-- 
 -Alan Kilian    kilian@cray.com 612.683.5499 (Work)
 "In 1969 We went to the moon and there was no air and only a bunch of
  dirt and WE LOVED IT!" -Tim Whitley talking about kids today and Apollo.
