Results 1 to 6 of 6

Thread: Problem in bitmap rotation...HELP

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2003
    Posts
    51

    Problem in bitmap rotation...HELP

    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?
    FiDz

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3
    Only Slightly Obsessive jemidiah's Avatar
    Join Date
    Apr 2002
    Posts
    2,431
    By the way, the size is:

    x = cos(rotation_angle)*height + sin(rotation_angle)*width
    y = sin(rotation_angle)*height + cos(rotation_angle)*width
    The time you enjoy wasting is not wasted time.
    Bertrand Russell

    <- Remember to rate posts you find helpful.

  4. #4
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    oops.. i didn't notice this earlier, but the first term in y and yrotate should be negated, shouldn't it?
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  5. #5
    Only Slightly Obsessive jemidiah's Avatar
    Join Date
    Apr 2002
    Posts
    2,431
    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.
    The time you enjoy wasting is not wasted time.
    Bertrand Russell

    <- Remember to rate posts you find helpful.

  6. #6
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    actually, its quite important that the first term is negated, or you will have it oscillate along a diagonal line rather than rotated.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width