Why do the coordinates swap when doing matrix multiplication while rotating a rectangle? #1145
-
I am applying the derotation matrix to a rectangle on a page that is rotated 270 degrees, however I am noticing some strange behavior in the output of that rectangle. In this case, the derotation matrix is Matrix(0, 1, -1, 0, h, 0) However, when doing the matrix multiplication by hand for each point, the result is: [x1, y1, 1] * Matrix(0, 1, -1, 0, h, 0) = [h-y1, x1] [x2, y2, 1] * Matrix(0, 1, -1, 0, h, 0) = [h-y2, x2] While [h-y2, x1, h-y1, x2] and [h-y1, x1, h-y2, x2] are functionally the same rectangle (albeit with different corners), why is this swap of the x values done? Furthermore, how is this done mathematically in the code? What rule is used to swap these coordinates? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Your manual multiplication - corner point by corner point - leads to an "infinite" rectangle, see documentation. |
Beta Was this translation helpful? Give feedback.
Your manual multiplication - corner point by corner point - leads to an "infinite" rectangle, see documentation.
The logic takes care that the result rect is defined by the diagonal of the points top-left and bottom-right.
To see the algorithm (which ultimately is written in C), lookup
fz_transform_rect
in MuPDF source code.