I have an array of size n^2 representing a square grid of size nxn.
I want to get from any square (0 to (n^2)-1) to the top-right most square you can get to moving diagonally in a straight line.
I already figured out that to get to the top-left most square is to take the current square x and the top-left most square is x%(n+1).
Does anyone know a similar method for top-right most square? Thanks!
If I understood at all what you're trying to achieve, all you need to do is connect the two points with a straight line and using the line formulas calculate the coordinates of the cells that it goes through. You may use for this the Bresenham's line drawing algorithm.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With