I have a matrix of [ n x m ] elements where center may not be on coordinate(x,y) 0,0:
<?php
$matrix_yx = array(
21 => array(10,11,12),
22 => array(10,11,12),
23 => array(10,11,12),
24 => array(10,11,12)
);
$origin_yx = array(23,11);
?>
I'm trying to write a function to pass as input
- the matrix
- pivot coordinate to be used as fulcrum
- eventually the rotation in degree (that can be only 90, 180 or 270)
So, considering a representation of matrix (x,y) elements:
y
^
| 10,24 11,24 12,24
| 10,23 >11,23< 12,23
| 10,22 11,22 12,22
| 10,21 11,21 12,21
+-----------------------> x
I need to rotate it of 90' degree clockwise around point (11,23) basically obtaining a new matrix like this:
y
^
| 09,24 10,24 11,24 12,24
| 09,23 10,23 >11,23< 12,23
| 09,22 10,22 11,22 12,23
+-------------------------------> x
I'm a little bit confused as if the (x,y) origin would be on coordinate (0,0) then it would be simple as
(x,y) = (11,23)
translate of 90' around (0) i would obtain
function Rotate($matrix) {
list($x,y) = array($y,-$x);
(x,y) = (23,-11);
}
but then what I have to consider if I want to pass a different pivot coordinate?
function Rotate($matrix, $pivot_x, $pivot_y) {
//-- (...)
}
In case I would have to transpose the matrix of 180 or 270 degree (instead of 90) then function will be called 2 or 3 times... unless obviously there's a smarter approach (that I'm sure exists but - at the moment - not in my mind).