Does anyone know how i would go about rotating an image 90 degrees clockwise and anticlockwise as i am finding it hard to find information on it

i am using borland c++ builder

Thanks

Printable View

- 03-24-2007peckitt99Rotation
Does anyone know how i would go about rotating an image 90 degrees clockwise and anticlockwise as i am finding it hard to find information on it

i am using borland c++ builder

Thanks - 03-24-2007Benzakhar
trigonometry

lets say you have a pixel at x , y. where (0, 0) is top left. (w, h) is width height. (a,b) = (x-w/2, h/2 - y)

where m is the length from (0, 0) defined at center of image to pixel

x' = mcos(k+90) = -sin(k)m = -b

y' = msin(k+90) = mcos(k) = a

apply transformation

x'' = x' + w/2 = w/2 - b = w/2 - [h/2 - y] = w/2 + y - h/2

y'' = h/2 - y' = h/2 - a = h/2 - [x/2 - w/2] = h/2 + w/2 - x/2

your final points x'' and y'' are the new coordinates. For better effect you might want to do a similar thing except assume you have a point go backward to find what pixel should go there. This way it will eliminate "white spots", and look more continious. - 03-25-2007Wraithan
Um, or just take the container holding the individual pixels and put them into a new container where the width == height of the original, and height == width of the original.

Say you have a 3 by 4 pixel image (very simple)

Code:`1 2 3`

4 5 6

7 8 9

10 11 12

- 03-25-2007peckitt99
yeah i think i understand what you mean - i am unsure how i would implement this tho - can you give me a few hints on how to cover come this?

- 03-25-2007KONI
Basically, if you have an pixel with coordinates x,y and you want to get the pixel coordinates after an rotation of alpha degrees, you multiply the coordinates in an 3 dimensional space by the following matrix:

Attachment 7159

What you have to do is create an destination image with the same dimensions as your original image (or different dimensions if you calculate the bounding box of the 4 corner pixels rotated by that matrix) and then for each pixel of the destination image, you apply the inverted rotation matrix to find the source pixel.

The code would look like this:

1. Calculate the inverse of the rotation matrix:

2. Create an empty image with the same dimensions as your original image

3.

Code:`for (i = 0; i < width; i++)`

{

for (j = 0; j < height; j++)

{

pixel(i,j) = InverseRotation(i,j);

}

}

But seeing what you did with the last thread I tried to help you, instead of trying to understand how things really work, you try to find a function somewhere that does the job for you.