Draw Polygon not positioned at top right

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
deadpickle
Posts: 5
Joined: 2013-09-15T21:19:49-07:00
Authentication code: 6789

Draw Polygon not positioned at top right

Post by deadpickle »

I am using Magick++ 6.7.7 Q16 to try and draw a ploygon on an image. Here is the code (it is a function of a larger program):

Code: Select all

void DoublyConnectedEdgeList::MakeImage()
{
	extern const double BOUNDBOX[4];
	extern const int XPIXELS;
	extern const int YPIXELS;
	int gridWidthX;
	int gridWidthY;

	Image voronoiImage( Geometry(XPIXELS, YPIXELS), Color(MaxRGB, MaxRGB, MaxRGB, 0));
	voronoiImage.strokeColor("black");
	voronoiImage.fillColor("white");
	voronoiImage.strokeWidth(10);

	//calc pixels per grid
	gridWidthX = XPIXELS / (BOUNDBOX[2] - BOUNDBOX[0]+2);
	gridWidthY = YPIXELS / (BOUNDBOX[3] - BOUNDBOX[1]+2);

	list<Coordinate> vorCoords;
	list<Drawable> vorPolygon;

	vorCoords.push_back(Coordinate(1*gridWidthX,1*gridWidthY));
	vorCoords.push_back(Coordinate(9*gridWidthX,1*gridWidthY));
	vorCoords.push_back(Coordinate(9*gridWidthX,9*gridWidthY));
	vorCoords.push_back(Coordinate(1*gridWidthX,9*gridWidthY));
	vorCoords.push_back(Coordinate(1*gridWidthX,1*gridWidthY));
	vorPolygon.push_back(DrawablePolygon(vorCoords));
	voronoiImage.draw(vorPolygon);

	//since Magick upper left is 0,0 this will set it to a standard Cartesian
	voronoiImage.flip();

	cout << "Write Image..." << '\n';
	voronoiImage.magick("png");
	voronoiImage.write("voronoidiagram.png");
}
When I look at the image the top right of the polygon is skewed as well as the bottom left. This seems to only happen with polylines and polygons, if I draw 4 lines everything is as expected
Image

BOUNDBOX is [0,0,8,8] and YPIXELS = 480, XPIXELS = 640. I cant figure why this is happening and I hope its something someone else has had happen to them. Thanks for the help.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Draw Polygon not positioned at top right

Post by Bonzo »

I would try something simple like drawing the polygon without all your variables. A simple convert with hard coded positions would be the best place to and see what happens. This will prove if it is an Imagemagick problem or a problem with your code.
deadpickle
Posts: 5
Joined: 2013-09-15T21:19:49-07:00
Authentication code: 6789

Re: Draw Polygon not positioned at top right

Post by deadpickle »

I hardcoded the same box:

Code: Select all

vorCoords.push_back(Coordinate(64.0,48.0));
	vorCoords.push_back(Coordinate(576.0,48.0));
	vorCoords.push_back(Coordinate(576.0,432.0));
	vorCoords.push_back(Coordinate(64.0,432.0));
	vorCoords.push_back(Coordinate(64.0,48.0));
and got the same results. Which I guess does not make me insane but is still not correct. Could this be an ImageMagick issue?
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: Draw Polygon not positioned at top right

Post by dlemstra »

What happens when you don't do the flip?
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Draw Polygon not positioned at top right

Post by Bonzo »

Probably does not help but this works for me using version 6.8.5 Q16

Code: Select all

convert -size 600x500 xc:none -fill none -stroke black -strokewidth 5 ^
-draw " polyline 64.0,48.0 576.0,48.0 576.0,432.0 64.0,432.0 64.0,48.0 " ^
result.png
This proves that Imagemagick version I used is working OK.

I suppose the only difference is all my co ordinates are on the same line in between the " " I know that the code can break sometimes if you split it over multiple lines in the wrong place.
deadpickle
Posts: 5
Joined: 2013-09-15T21:19:49-07:00
Authentication code: 6789

Re: Draw Polygon not positioned at top right

Post by deadpickle »

Image

not much change. Coordinate call for the point to be of type double and the call to draw is one line, so I dont think that is the issue since the method used is the same as the examples.
Post Reply