how to determine which cell in a grid a point belongs to I have a square area which is divided into an N X N grid.I need to insert a point (x,y) into this area.I tried to find out if there is a relation between the value of N and x,y coordinates sothat I can say this particular point belongs in the cell (0,3) or some other.
I tried plotting on a graph paper, assuming origin at left bottom corner,and tried to find which cell the point P(5.5,4.5) belongs to. When N=2 , it seems that the point P should be in cell(1,1) .If N=6, the point P belongs in cell(5,4) of grid.
I could not make out a relation between the values of N,coordinates of point and grid cell indices.Can someone please point me in the right direction?
 A: It depends on the size of the square. If the square $S$ consists of the points having $0 \le x,y < a$ (that is $S = [0,a)^2$), then the cell $C(i,j)$ (with $0 \le i,j < N$) has 
$$ C(i,j) = \left\{(x,y) \biggm| i\frac aN \le x < (i+1)\frac aN, \quad j \frac aN \le y < (j+1) \frac aN \right\} $$
That gives that 
$$ i = \def\fl#1{\left\lfloor#1\right\rfloor} \fl{\frac{xN}a},\; j = \fl{\frac{yN}a} $$
gives the cell of the point $(x,y) \in S$.
A: It is going to be the quotient of your point divided by the sample size.
So given a sample size $\Delta x$ and $\Delta y$ you take $(\lfloor\frac{x}{\Delta x}\rfloor+1,\lfloor\frac{y}{\Delta y}\rfloor+1)$, the +1 is because I do not think you are counting from 0.  As an example take the unit square with points at (0,0) and (1,1) and give it 2 divisions in the x-direction and 3 divisions in y-direction.  Take two points (0.6,0.4) and (0.21,0.798).  Then $\Delta x=0.5$ and $\Delta y=\frac{1}{3}$ and your cell calculation becomes $(\lfloor\frac{0.6}{0.5}\rfloor+1,\lfloor\frac{0.4}{\Delta y}\rfloor+1)=(2,2)$.  As for the second point $(\lfloor\frac{0.21}{0.5}\rfloor+1,\lfloor\frac{0.798}{\Delta y}\rfloor+1)=(1,3)$.
If you are no longer starting at zero you then need a simple translation.  
