circle parameters

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
User avatar
rmabry
Posts: 148
Joined: 2004-04-13T11:25:27-07:00

circle parameters

Post by rmabry »

One can use -draw to make a circle.

circle x0,y0 x1,y1

The first point x0,y0 is the center, the second point x1,y1 is any other point on the circle, this being used to calculate a radius. But there are many times when it is more convenient to simply specify a radius. (It is also pretty standard). How hard/dangerous would it be to allow an overloading of the syntax, in order to use this?

circle x0,y0 r


Rick
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: circle parameters

Post by anthony »

Would be nice... A cross between a 'point' and a 'circle'
Perhaps dot x,y,r

However as a solution try drawing a stroke with an appropriate stroke width and line end caps.

Code: Select all

    convert -size 100x100 xc: \
            -draw 'fill none  stroke black stroke-linecap round
                stroke-width 40    line 50,40 50,40.0001' \
         x:
And you have a circle that is 40 pixels in diameter!!!!

Note that you must draw a line of some distance even if it is very very tiny sub-pixel length, or IM will draw NOTHING!!

This use of very wide stroke-widths is examples in IM examples
http://imagemagick.org/Usage/draw/#simple

I found them interesting, but have not push them as a drawing technique.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
rmabry
Posts: 148
Joined: 2004-04-13T11:25:27-07:00

Re: circle parameters

Post by rmabry »

anthony wrote:Would be nice... A cross between a 'point' and a 'circle'
Perhaps dot x,y,r
Why not overload circle? For one thing, "dot" implies a fill, but I'd want to get a stroked and/or filled circle as a result.

It's hardly a big deal, since one can use "circle x,y, x+r,y", for example. It's just the principle of the thing. (Which principle it is, I cannot say.)
However as a solution try drawing a stroke with an appropriate stroke width and line end caps.

Code: Select all

    convert -size 100x100 xc: \
            -draw 'fill none  stroke black stroke-linecap round
                stroke-width 40    line 50,40 50,40.0001' \
         x:
And you have a circle that is 40 pixels in diameter!!!!

Note that you must draw a line of some distance even if it is very very tiny sub-pixel length, or IM will draw NOTHING!!
Heh, heh. Cute. And I suppose you can use another one on top of it with a different color to fake a stroke.

So Anthony, you must be finally getting caught up on your IM messages if you can look at this one. :-)

Thanks,
Rick
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: circle parameters

Post by fmw42 »

in a shell script you could do:

radius=40
x0=some value
y0=some value
x1=`expr $x0 + $radius`
y1=$y0

convert ... -draw "circle $x0,$y0 $x1,$y1" ...
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: circle parameters

Post by anthony »

After mail, I have been doing about a page of User forum messages every few days (from oldest to newest), and today I caught up with that, so now I did the developers forum, where I can skip a lot more messages.

I have now caught up with both forums. But it is a long weekend here so it is only short lived.

I did add an announcement forum page, listing the major additions to IM examples, since I got back. Some I found very interesting. Fred also has been very busy too, considering the number of scripts he now has.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
rmabry
Posts: 148
Joined: 2004-04-13T11:25:27-07:00

Re: circle parameters

Post by rmabry »

fmw42 wrote:in a shell script you could do
Sure, lucky *nixers. I'm more inclined to PerlMagick these days, so it is not an issue even for my Windows-bound self.

But I guess I should have made it more clear that I was not looking for a way to do this, just kvetching at the syntax. Look at SVG, for instance. Almost every programmable package that does graphics I've seen uses (x,y), r.

So my question remains, why not allow both syntaxes?

Rick
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: circle parameters

Post by fmw42 »

Yes, I would love to see that also. It makes sense to me, too.

But the IM developers are very busy with backlog of things to do. It would be great if there were other software developers willing to contribute some time to such development.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: circle parameters

Post by anthony »

hint, hint. nudge, nudge. wink, wink!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: circle parameters

Post by anthony »

First the parameters are floating point. But remember that strokewidth is also a parameter, and is stroke color is set the circle make be stroke width wider that what you specify using x1,y1.

The radius can be set using either a x or y axis difference for the calculating the x1,y1 point.

And yes I would agree that being able to specify a radius instead of x1,y1 would make a lot more sense in a lot more situations. However if you are going to specify it in that way a different operational method would be needed.

However there is a work around. Specify stroke-width as the diameter of the circle wanted, then draw a line from x0,y0 to x0,y1 where y1=y0+epsilon where epsilon is VERY VERY small.

EG: Blue circle by 'diameter'

Code: Select all

  convert -size 100x100 xc: -stroke blue -strokewidth 50 \
                -draw 'stroke-linecap round line 50,50 50,50.00001'
                blue_circle.png
No it isn't a great solution either.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: circle parameters

Post by anthony »

Depend on the method chosen.

As a result of the above OLD discussion I generated a drawing circles section in Draw. Some require calculation, others do not for a fixed radius.
http://www.imagemagick.org/Usage/draw/#circles

See also the section above this on Symols
http://www.imagemagick.org/Usage/draw/#symbols
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply