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. Rotate rerctangle in Bitmap

Rotate rerctangle in Bitmap

Scheduled Pinned Locked Moved C / C++ / MFC
graphicshardwarehelpquestion
20 Posts 4 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.
  • C CPallini

    {10,10,10,10} as {left,top,right,bottom} values give an empty rectangle. :)

    If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
    This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
    [My articles]

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

    CPallini wrote:

    {10,10,10,10} as {left,top,right,bottom} values give an empty rectangle

    I am not passing the values directly. As it is a bitmap image,on that i am drawing the rectangle I am multiplying it :

    x1 = (A1 * sf); //i.e (10 * 33.03)
    x2 = (A2 * sf); //i.e (10 * 33.03)
    y1 = (B1 * sf); //i.e (10 * 33.03)
    y2 = (B2 * sf); //i.e (10 * 33.03)

    where sf is sf=(1024/31); //Its a bitmap image Then while drawing the rectangle,i start as (center.x-left)

    MoveToEx(pCellInfo->hDC,center.x-x1,center.y-y2,NULL); //(center.x-left)
    //(center.y-bottom)

    I hope you got it. Thanks Raj

    C 1 Reply Last reply
    0
    • R raju_shiva

      CPallini wrote:

      {10,10,10,10} as {left,top,right,bottom} values give an empty rectangle

      I am not passing the values directly. As it is a bitmap image,on that i am drawing the rectangle I am multiplying it :

      x1 = (A1 * sf); //i.e (10 * 33.03)
      x2 = (A2 * sf); //i.e (10 * 33.03)
      y1 = (B1 * sf); //i.e (10 * 33.03)
      y2 = (B2 * sf); //i.e (10 * 33.03)

      where sf is sf=(1024/31); //Its a bitmap image Then while drawing the rectangle,i start as (center.x-left)

      MoveToEx(pCellInfo->hDC,center.x-x1,center.y-y2,NULL); //(center.x-left)
      //(center.y-bottom)

      I hope you got it. Thanks Raj

      C Offline
      C Offline
      CPallini
      wrote on last edited by
      #8

      raju_shiva wrote:

      x1 = (A1 * sf); //i.e (10 * 33.03) x2 = (A2 * sf); //i.e (10 * 33.03) y1 = (B1 * sf); //i.e (10 * 33.03) y2 = (B2 * sf); //i.e (10 * 33.03)

      I see no rectangle here. :)

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
      [My articles]

      R 1 Reply Last reply
      0
      • C CPallini

        raju_shiva wrote:

        x1 = (A1 * sf); //i.e (10 * 33.03) x2 = (A2 * sf); //i.e (10 * 33.03) y1 = (B1 * sf); //i.e (10 * 33.03) y2 = (B2 * sf); //i.e (10 * 33.03)

        I see no rectangle here. :)

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
        This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
        [My articles]

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

        CPallini wrote:

        I see no rectangle here

        After getting all the values Here i am drawing the rectangle

        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);

        Thanks Raj

        C 1 Reply Last reply
        0
        • R raju_shiva

          CPallini wrote:

          I see no rectangle here

          After getting all the values Here i am drawing the rectangle

          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);

          Thanks Raj

          C Offline
          C Offline
          CPallini
          wrote on last edited by
          #10

          OK (sorry if I didn't get you). Now, what is the problem with your code (expected behaviour vs observed one)?. :)

          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
          This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
          [My articles]

          R 1 Reply Last reply
          0
          • C CPallini

            OK (sorry if I didn't get you). Now, what is the problem with your code (expected behaviour vs observed one)?. :)

            If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
            This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
            [My articles]

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

            Now i want to rotate it for the given degree.How can i do it. I am bit confused please help me Thanks Raj

            C 1 Reply Last reply
            0
            • R raju_shiva

              Now i want to rotate it for the given degree.How can i do it. I am bit confused please help me Thanks Raj

              C Offline
              C Offline
              CPallini
              wrote on last edited by
              #12

              You are defining the rectangle via offsets from center, that is

              P0={-x1,-y2}, P1{-x1, y1}, P2={x2,y1}, P3={x2,-y2}

              hence, if you wan't rotate with angle phi around the center, than you should compute:

              Pr = { x * cos(phi) + y * sin(phi), -x * sin(phi) + y * cos(phi)}

              i.e.:

              P0R= { -x1 * cos(phi) -y2*sin(phi), x1 * sin(phi) - y2 * cos(phi)}
              P1R =...
              P2R =...
              P3R =...

              and then connect the center+PiR points the way you did before. :)

              If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
              This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
              [My articles]

              R 1 Reply Last reply
              0
              • C CPallini

                You are defining the rectangle via offsets from center, that is

                P0={-x1,-y2}, P1{-x1, y1}, P2={x2,y1}, P3={x2,-y2}

                hence, if you wan't rotate with angle phi around the center, than you should compute:

                Pr = { x * cos(phi) + y * sin(phi), -x * sin(phi) + y * cos(phi)}

                i.e.:

                P0R= { -x1 * cos(phi) -y2*sin(phi), x1 * sin(phi) - y2 * cos(phi)}
                P1R =...
                P2R =...
                P3R =...

                and then connect the center+PiR points the way you did before. :)

                If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                [My articles]

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

                CPallini wrote:

                P0R= { -x1 * cos(phi) -y2*sin(phi), x1 * sin(phi) - y2 * cos(phi)}

                I am confused with it??? Now suppose my values are:

                x1 = 330,x2 = 330,y1=330,y2=330
                Origin(center.x,cebter.y) = Origin(525,454);

                I have to do the get the new x1,x2,y1,y2 before calling MoveToEx and LineTo Am i right?? i.e

                Pr = { x * cos(phi) + y * sin(phi), -x * sin(phi) + y * cos(phi)}

                for each x1,x2,y1,y2. Then call the function

                MoveToEx(pCellInfo->hDC,center.x-x1,center.y-y2,NULL); // where x1 = Pr1,x2=Pr2....y2 = Pr4
                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);

                Thanks Raj

                C 1 Reply Last reply
                0
                • R raju_shiva

                  CPallini wrote:

                  P0R= { -x1 * cos(phi) -y2*sin(phi), x1 * sin(phi) - y2 * cos(phi)}

                  I am confused with it??? Now suppose my values are:

                  x1 = 330,x2 = 330,y1=330,y2=330
                  Origin(center.x,cebter.y) = Origin(525,454);

                  I have to do the get the new x1,x2,y1,y2 before calling MoveToEx and LineTo Am i right?? i.e

                  Pr = { x * cos(phi) + y * sin(phi), -x * sin(phi) + y * cos(phi)}

                  for each x1,x2,y1,y2. Then call the function

                  MoveToEx(pCellInfo->hDC,center.x-x1,center.y-y2,NULL); // where x1 = Pr1,x2=Pr2....y2 = Pr4
                  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);

                  Thanks Raj

                  C Offline
                  C Offline
                  CPallini
                  wrote on last edited by
                  #14

                  Something like this

                  // rotate around center
                  double phi = atan(1.0) * 2/3; // 30 degrees
                  int x[4];
                  int y[4];
                  x[0] = -x1 * cos(phi) - y2 * sin(phi);
                  y[0] = x1 * sin(phi) - y2 * cos(phi);

                  x[1] = -x1 * cos(phi) + y1 * sin(phi);
                  y[1] = x1 * sin(phi) + y1 * cos(phi);

                  x[2] = x2 * cos(phi) + y1 * sin(phi);
                  y[2] = -x2 * sin(phi) + y1 * cos(phi);

                  x[3] = x2 * cos(phi) - y2 * sin(phi);
                  y[3] = -x2 * sin(phi) - y2 * cos(phi);

                  for (int i=0; i<4; i++)
                  {
                  x[i] += center.x;
                  y[i] += center.y;
                  }

                  MoveToEx(pCellInfo->hDC,x[3],y[3],NULL);
                  for (int i=0; i<4; i++)
                  {
                  LineTo(pCellInfo->hDC, x[i],y[i]);
                  }

                  I suppose. :)

                  If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                  This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                  [My articles]

                  R R 2 Replies Last reply
                  0
                  • R raju_shiva

                    MoveToEx(pCellInfo->hDC,center.x-x1,center.y-y2,NULL); // Here i will find the new axis from the center axis
                    // i.e (center.x point - x1,center.y point-y2)
                    //so that i get the start point from where i can start to draw rectangle
                    LineTo(pCellInfo->hDC,center.x-x1,center.y+y1); //From here i will draw the rectangle

                    I hope you got it,what i am trying to do. If i am doing wrong,please let me know, Thanks for your reply Raj

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

                    When I said "look at the actual values", I didn't mean the expressions, I meant the actual values. In other words, either add some code to print out the values when you call the function or put a breakpoint on the call and inspect the values in your debugger. Then you should be able to figure out what is wrong and work back to where your problem is.

                    Software rusts. Simon Stephenson, ca 1994.

                    R 1 Reply Last reply
                    0
                    • C CPallini

                      Something like this

                      // rotate around center
                      double phi = atan(1.0) * 2/3; // 30 degrees
                      int x[4];
                      int y[4];
                      x[0] = -x1 * cos(phi) - y2 * sin(phi);
                      y[0] = x1 * sin(phi) - y2 * cos(phi);

                      x[1] = -x1 * cos(phi) + y1 * sin(phi);
                      y[1] = x1 * sin(phi) + y1 * cos(phi);

                      x[2] = x2 * cos(phi) + y1 * sin(phi);
                      y[2] = -x2 * sin(phi) + y1 * cos(phi);

                      x[3] = x2 * cos(phi) - y2 * sin(phi);
                      y[3] = -x2 * sin(phi) - y2 * cos(phi);

                      for (int i=0; i<4; i++)
                      {
                      x[i] += center.x;
                      y[i] += center.y;
                      }

                      MoveToEx(pCellInfo->hDC,x[3],y[3],NULL);
                      for (int i=0; i<4; i++)
                      {
                      LineTo(pCellInfo->hDC, x[i],y[i]);
                      }

                      I suppose. :)

                      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                      [My articles]

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

                      Thanks a lot ,its working fine. Thanks Raj

                      C 1 Reply Last reply
                      0
                      • P Peter_in_2780

                        When I said "look at the actual values", I didn't mean the expressions, I meant the actual values. In other words, either add some code to print out the values when you call the function or put a breakpoint on the call and inspect the values in your debugger. Then you should be able to figure out what is wrong and work back to where your problem is.

                        Software rusts. Simon Stephenson, ca 1994.

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

                        Thank u peter for your reply.Its working fine now Raj

                        1 Reply Last reply
                        0
                        • R raju_shiva

                          Thanks a lot ,its working fine. Thanks Raj

                          C Offline
                          C Offline
                          CPallini
                          wrote on last edited by
                          #18

                          You are welcome. :)

                          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                          This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                          [My articles]

                          1 Reply Last reply
                          0
                          • C CPallini

                            Something like this

                            // rotate around center
                            double phi = atan(1.0) * 2/3; // 30 degrees
                            int x[4];
                            int y[4];
                            x[0] = -x1 * cos(phi) - y2 * sin(phi);
                            y[0] = x1 * sin(phi) - y2 * cos(phi);

                            x[1] = -x1 * cos(phi) + y1 * sin(phi);
                            y[1] = x1 * sin(phi) + y1 * cos(phi);

                            x[2] = x2 * cos(phi) + y1 * sin(phi);
                            y[2] = -x2 * sin(phi) + y1 * cos(phi);

                            x[3] = x2 * cos(phi) - y2 * sin(phi);
                            y[3] = -x2 * sin(phi) - y2 * cos(phi);

                            for (int i=0; i<4; i++)
                            {
                            x[i] += center.x;
                            y[i] += center.y;
                            }

                            MoveToEx(pCellInfo->hDC,x[3],y[3],NULL);
                            for (int i=0; i<4; i++)
                            {
                            LineTo(pCellInfo->hDC, x[i],y[i]);
                            }

                            I suppose. :)

                            If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                            This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                            [My articles]

                            R Offline
                            R Offline
                            Rick York
                            wrote on last edited by
                            #19

                            The code looks correct but I find it to be slightly offensive to me sensibilities. :) I'm just kidding. I usually make a function or method when I see a sequence of code repeated more than twice. Something like this is generic enough that I definitely would. Of course, it's not your job to put this is into a function. That is an exercise for the reader. ;)

                            C 1 Reply Last reply
                            0
                            • R Rick York

                              The code looks correct but I find it to be slightly offensive to me sensibilities. :) I'm just kidding. I usually make a function or method when I see a sequence of code repeated more than twice. Something like this is generic enough that I definitely would. Of course, it's not your job to put this is into a function. That is an exercise for the reader. ;)

                              C Offline
                              C Offline
                              CPallini
                              wrote on last edited by
                              #20

                              Rick York wrote:

                              he code looks correct but I find it to be slightly offensive to me sensibilities. Smile I'm just kidding. I usually make a function or method when I see a sequence of code repeated more than twice. Something like this is generic enough that I definitely would.

                              Nah, that's childish. You've to set up a linear algebra library, with vectors and rotation matrices, properly overloading the multiplication operator. Of course that's an exercise for you. ;P :laugh: On my defence, I wouldn't write such code repetitions in my own software (well, maybe I do in quick and dirty junk programs), the goal there was being as explicit as possible (the OP had doubts on the steps to take) :)

                              If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                              This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                              [My articles]

                              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