Get the reflection of a POINT M[row][col] on a SQUARE matrix M, of size N

47 Views Asked by At

I have the following 7 x 7 matrix, which I'll name M. It has a value of 1 at M[2,2].

       [[0, 0, 0, 0, 0, 0, 0],
        [0, 0, 0, 0, 0, 0, 0],
        [0, 0, 1, 0, 0, 0, 0],
        [0, 0, 0, 0, 0, 0, 0],
        [0, 0, 0, 0, 0, 0, 0],
        [0, 0, 0, 0, 0, 0, 0],
        [0, 0, 0, 0, 0, 0, 0]]

If I rotate the matrix 180 degrees I would get the REFLECTION of the matrix, and 1 would be now at M[4,4].

       [[0, 0, 0, 0, 0, 0, 0],
        [0, 0, 0, 0, 0, 0, 0],
        [0, 0, 0, 0, 0, 0, 0],
        [0, 0, 0, 0, 0, 0, 0],
        [0, 0, 0, 0, 1, 0, 0],
        [0, 0, 0, 0, 0, 0, 0],
        [0, 0, 0, 0, 0, 0, 0]]

I'm looking for a formula to find the REFLECTION OF A POINT on a square matrix without doing the actual 180 degree rotation to get the result. A function to which I could pass f(M[2,2]), and get f(M[4,4]). This function should map M[row][col] to M[reflected_row][reflected_col] for ALL the points that could have a reflection on a SQUARE matrix of size N.

Thanks

p.s. I using python with numpy

1

There are 1 best solutions below

2
On BEST ANSWER

A mathematical function that does the trick is simply

$$f:M_{i,j} \mapsto M_{N-i,N-j},$$

but perhaps you are looking for a function in Python that does this? In that case, either simply define it yourself or ask over at Stack Overflow.