This may not be the most efficient way, and I have not tested it in AHK.

Edit: I had to double check my numbers, and I had them wrong initially. Also, the points you gave in the little code box for dotAx and dotAy don't match the diagram above, so we shouldn't use the red AB line you drew to check my answer.

So if A is at (200,200) and B is at (300,450), what we do is calculate a slope. Rise over Run -- That's the ΔY/ΔX. (450-200)/(300-200). So that's 250/100 = 2.5. What's odd about this slope number is because the Y-axis values are inverted, a positive value for the slope here means it slants down from left to right. In grade school you'd think of a positive slope as increasing from left to right, not the case here. I don't know for sure, but I believe the math will all work out anyway. It's an arbitrary distinction which direction the Y axis is going in.

So you want an equation for the line. y=mx+b, essentially. We just found out m, the slope. Now we need b. Let's use coordinate A for the X and Y. 200 = 2.5(200) + b. 200 = 500 + b. b = -300.

Our line equation is y = 2.5x - 300. Now we just need to loop through all the x values and find their y's. Just quickly doing it for a few sample points:

200, 200

220, 250

240, 300

260, 350

280, 400

300, 450

So what do we do with this? Take the X value and find the column it's in. We do this with division by 50, in fact, ceiling should work to round to the correct whole number; we round up so a coordinate of (1,3) would get divided by 50 (something close to 0) and then rounded up to 1. Let's take point 3 for instance. 240/50 = 4.8 ; Ceil(240/50) = 5. We know we're in the 5th column. This means it's 41-50. Algebraically, you want to get to 41. This is done with

*column* (the 5) minus 1, times by 10, add 1.

`topcell:=(column-1)*10+1`

will be 41 when column variable is 5.

We want to start at the top cell because we'll essentially create an offset to get into the correct row. This is done with the Y value. Again, divide by 50 and Ceiling it. 300/50 = 6; Ceil(300/50) = 6. We want the 6th row, which is 5 below the top cell. So do

`targetcell:=topcell+row-1`

. This should give the result of 46. Cool, we're almost there.

We do that same process on all the points. Stick each result into an array, or a long string, and we remove the duplicates. If an array, see the first few posts of this thread (it veers off topic):

https://autohotkey.com/boards/viewtopic.php?f=5&t=39697 If it's a long string, you can use the

Sort command which can remove duplicates for you.

That should give you the answer you need.

You might need to worry about the exact definition of borders though. Are the coordinates a 0-based in your grid? Or are they 1-based? That is, is the top left corner (0,0) or is it (1,1)? If it's 0,0, then the bottom-right corner of the first cell is (49,49); the cell diagonally down and right from it would be (50,50) to (99,99). But if it's 1-based, then coordinates are (1,1) to (50,50) and (51,51) to (100,100). My math assumes it's in 1 base I believe, because I said that the 300//50 = 6th row; If it's 0-based, the Y ranges for each row would be 0-49, 50-99, 100-149, 150-199, 200-249, 250-299, 300-349. Which is actually the 7th row.