How to draw a circle with a specified radius?

Magick++ is an object-oriented C++ interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning Magick++.
Post Reply
Airon65
Posts: 75
Joined: 2017-02-26T02:19:38-07:00
Authentication code: 1151

How to draw a circle with a specified radius?

Post by Airon65 » 2017-04-10T05:05:19-07:00

As the documentation says:
DrawableCircle

double originX_, double originY_, double perimX_, double perimY_

Draw a circle using the stroke color and thickness using specified origin and perimeter coordinates. If a fill color is specified, then the object is filled.
As the Math says:
Perimeter of a circle is: 2 * PI * R, where R is states for radius.
Well, ok:

Code: Select all

	Magick::Image testImg( Magick::Geometry( 500, 500 ), Magick::Color( "white" ) );

	testImg.strokeColor( "red" );
	testImg.fillColor( Magick::Color( QuantumRange, QuantumRange, QuantumRange, 0 ) );
	testImg.strokeWidth( 1 );

	float centerX = 100, centerY = 100;
	float w = 100, h = 100;
	
	float R = 100;
	float circlePerimeter = 2 * M_PI * R;
	testImg.draw( Magick::DrawableCircle( centerX, centerY, circlePerimeter, circlePerimeter ) );

	testImg.write( "images/test-img.png" );
Wtf? It doesn't work like this. What's the perimeter gets the Magick::DrawableCircle?

snibgo
Posts: 9378
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to draw a circle with a specified radius?

Post by snibgo » 2017-04-10T07:16:42-07:00

It needs two pairs of coordinates. The first is the centre. The second is any point on the perimeter. For example, if you want the centre at 100,100, and radius 20 then these will all give the same circle:

100,100 120,100
100,100 100,120
100,100 80,100
100,100 100,80
snibgo's IM pages: im.snibgo.com

Post Reply