PDA

Click to See Complete Forum and Search --> : Problem in bitmap rotation...HELP


FiDz
Jan 13th, 2004, 01:44 AM
hi;
i am trying to rotate a bitmap, using the usual equations,
origin: x0,y0
current pixel: x1,y1

rule:
xRotate = cos(angle) * (x1-x0) - Sin(angle) (Y1-Y0) + X0
yRotate = Sin(angle) * (x1-x0) - Cos(angle)(y1-y0) + y0

the problem is that i get yRotate negative, or the point is out of boundaries of the new bitmap!!

can anyone give me a complete alg. to rotate a bitmap?

kedaman
Jan 13th, 2004, 08:31 AM
I hope you understand that you need a larger bitmap if you rotate any odd angles (that aren't right angled for square bitmaps or 180 degrees for rectangles), the rotated bitmap will be of dimensions you get by rotating two not opposing corners around its center and double the distance to it along the x axis resp y axis.

jemidiah
Jan 13th, 2004, 08:08 PM
By the way, the size is:

x = cos(rotation_angle)*height + sin(rotation_angle)*width
y = sin(rotation_angle)*height + cos(rotation_angle)*width

kedaman
Jan 13th, 2004, 09:26 PM
oops.. i didn't notice this earlier, but the first term in y and yrotate should be negated, shouldn't it?

jemidiah
Jan 14th, 2004, 12:36 AM
It's just a derived parametric algorithm (just ;)), meaning you can think of it parametrically. The basic parametric circle equation rotates differently depending on whether you use sin or cos in the x or y part of the equation, and whether you negate it. Negating the y value will only reverse the rotation and make it start at the opposite end vertically. Negating both would double reverse the rotation (keeping it as it was) and make it start at the opposite end diagonally. There really isn't any correct way I've ever seen, so it's really a matter of preference.

kedaman
Jan 14th, 2004, 12:25 PM
actually, its quite important that the first term is negated, or you will have it oscillate along a diagonal line rather than rotated.