Bob5421
Bob5421

Reputation: 9163

Applying a rotation to an image without sinus and cosinus

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

Answers (3)

Spektre
Spektre

Reputation: 51873

In graphics we usually use homogenuous transform matrices for tasks like this. So the algo is like this:

  1. create transform matrix

    holding all the transforms you want. For 2D it is 3x3 homogenuous transform matrix or 2x2 rotation matrix (no translations).

  2. 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

Zalman Stern
Zalman Stern

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

user1196549
user1196549

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

Related Questions