Groups | Blog | Home
all groups > dotnet drawing api > february 2004 >

dotnet drawing api : How to Rotate about an origin



James
2/28/2004 12:26:04 AM
Does anybody knows how to rotate about an origin with gdi+. I got a piece of
code that rotates, however it rotates everywhere except the origin.

g.RotateTransform(10);
g.DrawRectangle(pn, 10, 10,200,40);

The above code works except that it doesn't rotate about the origin. Can
somebody please shed some light on rotation for me?

James

Bob Powell [MVP]
2/28/2004 11:06:15 AM
All rotations happen about the origin unless you use the RotateAt method
which incidentally does a quick translation of that point to the origin,
rotates and shifts it back to its original position again.

If you want to rotate that rectangle about its own origin then do the
following..

RotateTransform(10);
TranslateTransform(10,10);
DrawRectangle(0,0,200,40);

To rotate the rectangle about it's centre...

TranslateTransform(-100,-20);
RotateTransform(10);
TranslateTransform(110,30);
DrawRectangle(0,0,200,40);

This months Well Formed has an article which will interest you on creating
and using a graphic transform stack and how to create complex graphic models
in which the parts have complex relationships to one another. It includes an
application called Graphics Explorer that demonstrates the principles.

http://www.bobpowell.net/currentissue.htm

--
Bob Powell [MVP]
Visual C#, System.Drawing

Check out February's edition of Well Formed.
Non-client drawing, Graphics Transform stack and Flood-Filling
http://www.bobpowell.net/currentissue.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

Read my Blog at http://bobpowelldotnet.blogspot.com

[quoted text, click to view]

Nilesh
3/4/2004 9:26:06 PM
AddThis Social Bookmark Button