How to rotate a rectangle in Bitmap
-
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
-
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
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 iscenter
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.
-
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 iscenter
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.
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