Which cell in a grid a point belongs to?

I have a square which is divided into an NxN grid and I have a dot. How I can find which cell this point belongs to? Assuming I know the boundaries of the square.

How to find the point belongs to the 3rd cell? Numbering cells inside the grid is random. Okay, I think to get number of cell (if takes variant from the example), it's 3 number of cell and divide it by 10 and than multiply by 2. The formula is y = floor( $$\frac{cell number}{width}*2$$) and do it for each cell, but what the next step?

• Hi and welcome to the site! Since this is a site that encourages and helps with learning, it is best if you show your own ideas and efforts in solving the question. Can you edit your question to add your thoughts and ideas about it? Don't worry if it's wrong - that's what we're here for. – 5xum Mar 5 at 9:29
• Also, don't get discouraged by the downvote. I downvoted the question and voted to close it because at the moment, it is not up to site standards (you have shown no work you did on your own). If you edit your question so that you show what you tried and how far you got, I will not only remove the downvote, I will add an upvote. – 5xum Mar 5 at 9:29
• @5xum Hi, I'm tried to add some my thoughts, sorry fom my bad english. – evaee Mar 5 at 9:37
• "Numbering cells inside the grid is random": how do you know the number of a cell ? – Yves Daoust Mar 5 at 10:02
• @YvesDaoust I mean that the number of cells may be random, from -100 to 100 for example, but I knew them, they given me as a matrix (2d array). – evaee Mar 5 at 10:04

For a point at (X, Y), the cell indexes are (X / S, Y / S), using integer division (if the numbers aren't integers, take the floor).
• @evaee: (7 / 10, 13 / 10) = (0, 1), assuming that the top-left square has its top left corner at the origin, like on your figure and unlike in your comment. – Yves Daoust Mar 5 at 10:21