On Feb 14, 3:47 am, "Anush" <itsanushshe...@[EMAIL PROTECTED]
> wrote:
> I have a square grid of unit size. If i have a line between any two
> points, how do i find out the number of the intersecting squares.
>
> -
> Anush
Well, if you label each cell from (0,0) to (N,N), you can convert from
the points to cell coordinates by dividing the point coordinates by
the width of a cell. Then all you need to do is find the ceiling of
the Euclidean distance between the two points--in other words, round
up to the nearest whole integer. This worked with a small test
sample, but you should probably test it with several test cases to
make sure that it works in all cases. I think that you can do a brute
force test using the method described here if you make the Z
coordiantes 0:
http://mathworld.wolfram.com/Line-PlaneIntersection.html


|