Rotate rerctangle in Bitmap
-
{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]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
-
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
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] -
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]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
-
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
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] -
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]Now i want to rotate it for the given degree.How can i do it. I am bit confused please help me Thanks Raj
-
Now i want to rotate it for the given degree.How can i do it. I am bit confused please help me Thanks Raj
You are defining the rectangle via offsets from
center
, that isP0={-x1,-y2}, P1{-x1, y1}, P2={x2,y1}, P3={x2,-y2}
hence, if you wan't rotate with angle
phi
around thecenter
, 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] -
You are defining the rectangle via offsets from
center
, that isP0={-x1,-y2}, P1{-x1, y1}, P2={x2,y1}, P3={x2,-y2}
hence, if you wan't rotate with angle
phi
around thecenter
, 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]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
-
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
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] -
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 rectangleI hope you got it,what i am trying to do. If i am doing wrong,please let me know, Thanks for your reply Raj
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.
-
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]Thanks a lot ,its working fine. Thanks Raj
-
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.
Thank u peter for your reply.Its working fine now Raj
-
Thanks a lot ,its working fine. Thanks Raj
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] -
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]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. ;)
-
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. ;)
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]