Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to rotate a rectangle in Bitmap

How to rotate a rectangle in Bitmap

Scheduled Pinned Locked Moved C / C++ / MFC
graphicshelptutorialquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    raju_shiva
    wrote on last edited by
    #1

    Hi sir, I have origin axis and x1,x2,y1,y2. I want to draw a rectangle and rotate it with the given degree.I am trying with this code,but i am not getting. Her is the code

    double x1,x2,y1,y2;
    sf=(1024/31);
    A1 = 10.00;
    A2 = 10.00;
    B1 = 10.00;
    B2 = 10.00;

    x1 = (A1 \* sf);
    x2 = (A2 \* sf);
    y1 = (B1 \* sf);
    y2 = (B2 \* sf);
    

    float Angle = 45.0;

    x1 = x1 * cos(Angle) + y1 * sin(Angle);
    y1 = -x1 * sin(Angle) + y1 * cos(Angle);
    x2 = x2 * cos(Angle) + y2 * sin(Angle);
    y2 = -x2 * sin(Angle) + y2 * cos(Angle);

    Origin(525,454); // center origin(center.x,center.y);
    MoveToEx(pCellInfo->hDC,center.x-x1,center.y-y2,NULL);

    LineTo(pCellInfo->hDC,center.x-x1,center.y+y1);
    LineTo(pCellInfo->hDC,center.x+x2,center.y+y1);
    LineTo(pCellInfo->hDC,center.x+x2,center.y-y2);
    LineTo(pCellInfo->hDC,center.x-x1,center.y-y2);

    If i test with this hard code values,i am getting the rectangle rotated

    MoveToEx(pCellInfo->hDC,525,289,NULL);// Angle 45 for reference
    LineTo(pCellInfo->hDC,360,454);
    LineTo(pCellInfo->hDC,525,619);
    LineTo(pCellInfo->hDC,690,454);
    LineTo(pCellInfo->hDC,525,289);

    how can i get the same values Thanks Raj Can some one help me

    P 1 Reply Last reply
    0
    • R raju_shiva

      Hi sir, I have origin axis and x1,x2,y1,y2. I want to draw a rectangle and rotate it with the given degree.I am trying with this code,but i am not getting. Her is the code

      double x1,x2,y1,y2;
      sf=(1024/31);
      A1 = 10.00;
      A2 = 10.00;
      B1 = 10.00;
      B2 = 10.00;

      x1 = (A1 \* sf);
      x2 = (A2 \* sf);
      y1 = (B1 \* sf);
      y2 = (B2 \* sf);
      

      float Angle = 45.0;

      x1 = x1 * cos(Angle) + y1 * sin(Angle);
      y1 = -x1 * sin(Angle) + y1 * cos(Angle);
      x2 = x2 * cos(Angle) + y2 * sin(Angle);
      y2 = -x2 * sin(Angle) + y2 * cos(Angle);

      Origin(525,454); // center origin(center.x,center.y);
      MoveToEx(pCellInfo->hDC,center.x-x1,center.y-y2,NULL);

      LineTo(pCellInfo->hDC,center.x-x1,center.y+y1);
      LineTo(pCellInfo->hDC,center.x+x2,center.y+y1);
      LineTo(pCellInfo->hDC,center.x+x2,center.y-y2);
      LineTo(pCellInfo->hDC,center.x-x1,center.y-y2);

      If i test with this hard code values,i am getting the rectangle rotated

      MoveToEx(pCellInfo->hDC,525,289,NULL);// Angle 45 for reference
      LineTo(pCellInfo->hDC,360,454);
      LineTo(pCellInfo->hDC,525,619);
      LineTo(pCellInfo->hDC,690,454);
      LineTo(pCellInfo->hDC,525,289);

      how can i get the same values Thanks Raj Can some one help me

      P Offline
      P Offline
      Peter_in_2780
      wrote on last edited by
      #2

      I can see a few problems straight up: 1. [Probably not important] If sf is an int, then that's probably not what you want. 2. Trig functions expect angles in radians not degrees, so an angle of 45.0 is probably not what you want. 3. Where is center being set? It could be some wild value so that all the drawing is offscreen. Look at the actual values you are passing to MoveToEx and LineTo.

      Software rusts. Simon Stephenson, ca 1994.

      R 1 Reply Last reply
      0
      • P Peter_in_2780

        I can see a few problems straight up: 1. [Probably not important] If sf is an int, then that's probably not what you want. 2. Trig functions expect angles in radians not degrees, so an angle of 45.0 is probably not what you want. 3. Where is center being set? It could be some wild value so that all the drawing is offscreen. Look at the actual values you are passing to MoveToEx and LineTo.

        Software rusts. Simon Stephenson, ca 1994.

        R Offline
        R Offline
        raju_shiva
        wrote on last edited by
        #3

        Peter_in_2780 wrote:

        Look at the actual values you are passing to MoveToEx and LineTo.

        Peter_in_2780 wrote:

        If sf is an int

        No its double.

        Peter_in_2780 wrote:

        Trig functions expect angles in radians not degrees,

        I have changed it to

        int a = 45;
        float Angle = ( 3.142 * a ) / 180;

        Peter_in_2780 wrote:

        Where is center being set?

        I am gettin g the center by calculating the bitmag as..

        center.x=(((pCellInfo->rcBitmapRect.right-pCellInfo->rcBitmapRect.left)/2)+pCellInfo->rcBitmapRect.left);
        center.y=(((pCellInfo->rcBitmapRect.bottom-pCellInfo->rcBitmapRect.top)/2)+pCellInfo->rcBitmapRect.top);

        Thanks Raj

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups