Jump to content

Polygon Rotation?


AppDev

Recommended Posts

Hi,

I am new to Paint.net Plugin development. I have viewed few tutorials to code in C# using CodeLab. I have write a simple program that draw an Arrow on the canvas using different parameters. The code for drawing arrow is as follow.

Rectangle selection = EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt();

dst.CopySurface(src,rect.Location,rect);

// create a Brush to draw a filled Polygon

SolidBrush myBrushColor1 = new SolidBrush(Amount9);

// create a GDI+ graphics surface

Graphics g = new RenderArgs(dst).Graphics;

g.Clip = new Region(rect);

// Code for Drawing Arrow

g.FillPolygon(myBrushColor1, new PointF[] {

new PointF(Amount1, Amount2),

new PointF(Amount1+Amount4, Amount2),

new PointF(Amount1+Amount4, Amount2-Amount5),

new PointF(Amount1+Amount4+Amount6, Amount2-Amount5),

new PointF(Amount1, Amount2-Amount5-Amount8)

});

By using the above code the Arrow is drawn on the canvas successfully. Now I want to rotate the Drawn arrow to any specified angle. I have used g.RotateTransform(Angle); but it rotate the arrow according to the starting point of the canvas, but i want to rotate the arrow around its center point. Any help will be appreciated.

Thanks,

Edited by AppDev
Link to comment
Share on other sites

Well, not translate per se. Probably RotateAt(). You may need to use stuff on Matrix and not just Graphics.

In any case, you need to modify the transform on the Graphics object. It's simple, albeit obnoxious, matrix math.

The Paint.NET Blog: https://blog.getpaint.net/

Donations are always appreciated! https://www.getpaint.net/donate.html

forumSig_bmwE60.jpg

Link to comment
Share on other sites

Well, not translate per se. Probably RotateAt(). You may need to use stuff on Matrix and not just Graphics.

In any case, you need to modify the transform on the Graphics object. It's simple, albeit obnoxious, matrix math.

Not really necessary. TranslateTransform() will move the origin of the Graphics object, then RotateTransform() will rotate it about the new origin.

xZYt6wl.png

ambigram signature by Kemaru

[i write plugins and stuff]

If you like a post, upvote it!

Link to comment
Share on other sites

Thank you all for your replies. I have used g.TranslateTransform(p1, p2); and g.RotateTransform(angle); but it still not rotating the arrow around a specific point. I have attached the screenshots of the problem.

I have drawn the arrow on point (400, 400).

  1. In the 1st screenshot I have set g.TranslateTransform(0, 0); and g.RotateTransform(0); and the arrow is positioned right where it is drawn with no rotation. i.e. (400,400).
  2. In the 2nd screenshot I have set g.TranslateTransform(0, 0); and g.RotateTransform(20); and the arrow is positioned Below the position (400, 400) with a little angle.
  3. In the 3rd screenshot I have set g.TranslateTransform(400, 400); and g.RotateTransform(20); and most of the arrow is positioned outside the canvas.

Am I missing something here? What values I will use to correctly do this? Also When I declare an object of Matrix class it gives an error "The type or namespace "Matrix" could not be found"

post-86698-132170461342_thumb.jpg

post-86698-132170462152_thumb.jpg

post-86698-132170463517_thumb.jpg

Edited by AppDev
Link to comment
Share on other sites

Hi all,

I have figured it out. I was actually drawing polygon at point (400,400) and then applying transform to it which was causing rotation problem. Now i have drawn the Polygon at Point (0,0) and applied TranslateTranform(400,400), now polygon is rotating around point (400, 400).

Thanx all.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...