Page 1 of 1

How to draw a circle with a specified radius?

Posted: 2017-04-10T05:05:19-07:00
by Airon65
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?

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

Posted: 2017-04-10T07:16:42-07:00
by snibgo
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