draw circle radius

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
bonobo2000
Posts: 6
Joined: 2011-01-19T13:44:40-07:00
Authentication code: 8675308

draw circle radius

Post by bonobo2000 »

I use

Code: Select all

convert -size 8x8 xc: -draw "translate 0,0 circle 0,0 3,0" ./bla.png
I would expect a circle with a radius of 3 pixels. However, I am getting is a circle with 4 pixels radius. While this might or not be a bug, it certainly doesn't fit the second example shown in the documentation in http://www.imagemagick.org/Usage/draw/#circles .
cheers
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: draw circle radius

Post by fmw42 »

I think that the actual radius value is added to the center pixel to get to the circle perimeter.

0 1 2 3

So from 0 you add 3 more to get to the radius of 3, which is the 4th pixel.

Or perhaps better you can think of it as from 0 to 1 is distance 1, 1 to 2 is distance 1 and 2 to 3 is distance 1. So adding up all the distances your get a total distance of 3. So the distance or change is 3, and starting from 0. So it includes 4 pixels.

I get the same thing as described from above from both commands that follow

Code: Select all

convert -size 8x8 xc:black -fill white -draw "translate 0,0 circle 0,0 3,0" bla.png
convert -size 8x8 xc:black -fill white -draw "circle 0,0 3,0" bla2.png
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: draw circle radius

Post by snibgo »

The difficulty is that "radius" (like "diameter" and most other distance) is usually defined as the distance between centres of pixels, not the total distance including the thickness of the pixels at both ends.

The documentation http://www.imagemagick.org/script/comma ... s.php#draw says:
Give the center and any point on the perimeter (boundary).
So your centre is at 0,0 and the circle passes through 0,3. The distance between the centres of these pixels is 3.
snibgo's IM pages: im.snibgo.com
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: draw circle radius

Post by snibgo »

Here's another way of thinking:

Code: Select all

convert -size 9x9 xc: -draw "circle 4,4 4,7" -scale 500x500 circrad3.png
Image

Simplistically, the radius is 3. But what is the diameter, including the full width or height of the pixels? That diameter is 7. So that radius (from the dead centre, to any extreme) is 3.5.

So it really depends on how we define "radius" (and "diameter").
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: draw circle radius

Post by fmw42 »

Another way to look at it is that from the center of the center pixel to the center of the far right pixel is exactly 3. So if you consider the "circle" perimeter to have one pixel thickness, then the distance from the very center of the circle to middle of the perimeter pixel is 3.
Post Reply