Reputation: 9163
I have read somewhere (but i do not remember where exactly) it was possible to rotate pixels of an image by applying a single matrix (just additions and multiplication).
This was done without sinus and cosinus functions.
I am wondering if i had a dream or if this is really possible...
Thanks
Upvotes: 0
Views: 492
Reputation: 51873
In graphics we usually use homogenuous transform matrices for tasks like this. So the algo is like this:
create transform matrix
holding all the transforms you want. For 2D it is 3x3 homogenuous transform matrix or 2x2 rotation matrix (no translations).
process all destination pixels
basically copy pixel from source to destination image, but the loops are looping every destination pixel (to avoid rounding holes). So let the loop goes through (x,y)
so you just copy pixels ...
dst[y][x] = src[y'][x']
where:
(x',y') = Matrix2x2 * (x,y)
or
(x',y',w) = Matrix3x3 * (x,y,1)
It does not matter if you use 2x2 or 3x3 matrix or hardcoded multiplication (as in example) see:
but you need to use sin,cos
for the matrix values (once per rotation). The only rotation without sin,cos
is rotation by 90 deg
Where:
(x',y') = (-y,x)
or:
(x',y') = (y,-x)
Upvotes: 0
Reputation: 3191
3x3 transform matrices are the standard abstraction in 2D graphics work. See: https://en.m.wikipedia.org/wiki/Transformation_matrix . Whether this avoids sine and cosine is a bit up for debate as one typically uses those trigonometric functions to construct a rotation matrix if starting from an angle.
Upvotes: 1
Reputation:
Yes, and no.
You apply a rotation with a matrix, as this is an affine transformation (https://en.wikipedia.org/wiki/Affine_transformation).
But if the rotation amplitude is specified by an angle, you can't avoid the use of the trigonometric functions to evaluate the coefficients.
A last remark: this is completely harmless, why worry ?
Upvotes: 0