A simple rotation is always about the origin. A simple rotation (in 2D) is given by the following transformation matrix (I'm using homogenous coordinates here):
? r1 -r2 0 ?
R = ? r2 r1 0 ?
? 0 0 1 ?
r1
and r2
are related in that together they form a unit vector (r1^2 + r2^2 = 1
). When putting coordinates through that transformation, they are rotated about the origin. For example, given a vector p
, we rotate it by left-multiplying it by R
.
If you want to rotate around another point, say (c1
, c2
), you need to translate the coordinates such that this new point moves to the origin, then apply the rotation, then translate back:
? 1 0 c1 ? ? r1 -r2 0 ? ? 1 0 -c1 ?
T' R T = ? 0 1 c2 ? ? r2 r1 0 ? ? 0 1 -c2 ?
? 0 0 1 ? ? 0 0 1 ? ? 0 0 1 ?
Multiplying this out gives:
? r1 -r2 -r1*c1+r2*c2+c1 ? ? 1 0 -r1*c1+r2*c2+c1 ? ? r1 -r2 0 ?
T' R T = ? r2 r1 -r2*c1-r1*c2+c2 ? = ? 0 1 -r2*c1-r1*c2+c2 ? ? r2 r1 0 ?
? 0 0 1 ? ? 0 0 1 ? ? 0 0 1 ?
So, we can see that we can instead simply rotate around the origin, and then translate the result in some appropriate way to get the same result as if we were rotating around our chosen center of rotation.
Given any image processing library function that rotates the image and gives the full result (i.e. its output image contains all input data), we can recreate the result of rotating around an arbitrary point by cutting this result to the input size with the appropriate offset.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…