Circle - Maple Help

ImageTools[Draw]

 Circle
 ImageTools:-Draw Circle Primitive
 SolidCircle
 ImageTools:-Draw Solid Circle Primitive

 Calling Sequence Circle( image, xCenter, yCenter, diameter, opts ) SolidCircle( image, xCenter, yCenter, diameter, opts )

Parameters

 image - ImageTools:-Image xCenter - numeric yCenter - numeric diameter - numeric color - (optional) see description thickness - (optional) numeric := 1.0

Description

 • After first creating an image using ImageTools:-Create, or loading an image with ImageTools:-Read, drawing operations can be performed on it using a number of primitives (functions that draw one kind of object). The first argument to each primitive is the image itself, as returned by Create or Read.
 • The Circle and SolidCircle Primitives draw either an outlined or solid circle around a specified center point and with a specified diameter. Like the SolidRectangle primitive, the circle is perceptually entirely within the bounds specified by the center point and diameter.
 • The xCenter and yCenter arguments give the coordinates of the circle's center, and the diameter argument specifies its diameter in pixels.
 • The color argument can be specified in one of several forms:

 gray A numeric value between 0 and 1 specifying a shade of gray. The value 0 corresponds to black, and 1 to white. [r,g,b] A list of three numeric values between 0 and 1 specifying the red, green, and blue components separately. [r,g,b,α] A list of four numeric values between 0 and 1 specifying the red, green, blue, and opacity (alpha) separately. When the opacity is less than 1, the color will be blended with the existing content of the image. A value of type ColorTools:-Color. ColorTools:-Color argument(s) Any form accepted by the ColorTools:-Color constructor, such as a string giving a color name (e.g. "red", palette and color name (e.g. "Niagara DarkOrchid"), or palette and color number (e.g. "Nautical 1"). Two argument forms are accepted as well, but then it is necessary to always use the keyword form of the color argument, since otherwise the two arguments will be interpreted as two separate arguments to the drawing primitive. For example, color=("HSV",[0.5,0.6,0.6]).

 • The thickness option specifies the thickness of the boundary line. The entire boundary will be rendered within the specified diameter. Increasing the boundary thickness will not make the exterior of the circle any larger; all the variation in thickness is towards the interior.
 • The color and thickness options are best provided as keyword equations, but can also be provided as positional arguments in the 5th and 6th positions respectively.

Package Usage

 • This function is part of the ImageTools:-Draw package, so it can be used in the short form Circle(..) only after executing the command with(ImageTools:-Draw). However, it can always be accessed through the long form of the command by using ImageTools:-Draw:-Circle(..).

Examples

 > $\mathrm{with}\left(\mathrm{ImageTools}\right):$
 > $\mathrm{with}\left(\mathrm{ImageTools}:-\mathrm{Draw}\right):$

Circle with thick edge.

 > $\mathrm{img}≔\mathrm{Create}\left(240,320,\mathrm{channels}=3,\mathrm{background}=\mathrm{white}\right):$
 > $\mathrm{Circle}\left(\mathrm{img},160,120,240-64,\mathrm{color}=0.5,\mathrm{thickness}=3\right)$
 > $\mathrm{Embed}\left(\mathrm{img}\right)$

for the next step, ensure that you have appropriate permissions for the directory you will write to.

 > $\mathrm{Write}\left("circ1.png",\mathrm{img}\right)$
 ${6056}$ (5.1)

Solid gray circle.

 > $\mathrm{img}≔\mathrm{Create}\left(240,320,\mathrm{channels}=3,\mathrm{background}=\mathrm{white}\right):$
 > $\mathrm{SolidCircle}\left(\mathrm{img},160,120,240-64,\mathrm{color}=0.5\right)$
 > $\mathrm{Embed}\left(\mathrm{img}\right)$

Supporting Functions for the Examples

Draw a red crosshair centered at (x*scale,y*scale).

 > crossHair := proc( img :: Array, x :: numeric, y :: numeric, scale :: numeric )    uses ImageTools:-Draw;    Line(img,(x-1.5)*scale,y*scale,(x+1.5)*scale,y*scale,         color="red",thickness=1.5);    Line(img,x*scale,(y-1.5)*scale,x*scale,(y+1.5)*scale,         color="red",thickness=1.5) end:

Draw a background grid with specified interval.

 > gridFill := proc( img :: Array, interval :: numeric )    local x, y, w, h;    uses ImageTools:-Draw;    w, h := Width(img), Height(img);    for x from interval by interval while x < w do        Line(img,x,0,x,h,color=[0,1,1,0.25])    od;    for y from interval by interval while y < h do        Line(img,0,y,w,y,color=[0,1,1,0.25])    od end:

Unzoomed image to hold all four of the following circles.

 > $\mathrm{img4}≔\mathrm{Create}\left(62,80,\mathrm{channels}=3,\mathrm{background}=\mathrm{white}\right):$

The images below will be generated at 20 pixels width and 15 pixels height, magnified by a factor of 16, and then augmented with red crosshairs to show the mathematical corners of the circles.

Zoomed circle with thin edge.

 > $\mathrm{img}≔\mathrm{Create}\left(15,20,\mathrm{channels}=3,\mathrm{background}=\mathrm{white}\right):$
 > $\mathrm{Circle}\left(\mathrm{img},10,7,10,\mathrm{color}=0.5,\mathrm{thickness}=1\right)$
 > $\mathrm{img4}\left[9..23,11..30\right]≔\mathrm{img}:$
 > $\mathrm{img}≔\mathrm{Scale}\left(\mathrm{img},16,\mathrm{method}=\mathrm{nearest}\right):$
 > $\mathrm{gridFill}\left(\mathrm{img},16\right)$
 > $\mathrm{crossHair}\left(\mathrm{img},10,7,16\right)$
 > $\mathrm{crossHair}\left(\mathrm{img},5,2,16\right)$
 > $\mathrm{crossHair}\left(\mathrm{img},15,12,16\right)$
 > $\mathrm{Embed}\left(\mathrm{img}\right)$

Zoomed circle with thick edge.

 > $\mathrm{img}≔\mathrm{Create}\left(15,20,\mathrm{channels}=3,\mathrm{background}=\mathrm{white}\right):$
 > $\mathrm{Circle}\left(\mathrm{img},10,7,10,\mathrm{color}=0.5,\mathrm{thickness}=2.5\right)$
 > $\mathrm{img4}\left[9..23,51..70\right]≔\mathrm{img}:$
 > $\mathrm{img}≔\mathrm{Scale}\left(\mathrm{img},16,\mathrm{method}=\mathrm{nearest}\right):$
 > $\mathrm{gridFill}\left(\mathrm{img},16\right)$
 > $\mathrm{crossHair}\left(\mathrm{img},10,7,16\right)$
 > $\mathrm{crossHair}\left(\mathrm{img},5,2,16\right)$
 > $\mathrm{crossHair}\left(\mathrm{img},15,12,16\right)$
 > $\mathrm{Embed}\left(\mathrm{img}\right)$

Both of these two circles above have the same center coordinates and same diameter. Since the center coordinates are integers, and the diameter is an integer multiple of two, the left, right, top, and bottom edges coincide exactly with pixel boundaries. In the second circle, notice that the edge pixels are identical to those of the first circle; the additional edge thickness has not made the circle any larger.

Zoomed solid circle with integer center and bounds.

 > $\mathrm{img}≔\mathrm{Create}\left(15,20,\mathrm{channels}=3,\mathrm{background}=\mathrm{white}\right):$
 > $\mathrm{SolidCircle}\left(\mathrm{img},10,7,10,\mathrm{color}=0.5\right)$
 > $\mathrm{img4}\left[40..54,11..30\right]≔\mathrm{img}:$
 > $\mathrm{img}≔\mathrm{Scale}\left(\mathrm{img},16,\mathrm{method}=\mathrm{nearest}\right):$
 > $\mathrm{gridFill}\left(\mathrm{img},16\right)$
 > $\mathrm{crossHair}\left(\mathrm{img},10,7,16\right)$
 > $\mathrm{crossHair}\left(\mathrm{img},5,2,16\right)$
 > $\mathrm{crossHair}\left(\mathrm{img},15,12,16\right)$
 > $\mathrm{Embed}\left(\mathrm{img}\right)$

Zoomed solid circle with non-integer center and bounds.

 > $\mathrm{img}≔\mathrm{Create}\left(15,20,\mathrm{channels}=3,\mathrm{background}=\mathrm{white}\right):$
 > $\mathrm{SolidCircle}\left(\mathrm{img},10.3,7.4,11,\mathrm{color}=0.5\right)$
 > $\mathrm{img4}\left[40..54,51..70\right]≔\mathrm{img}:$
 > $\mathrm{img}≔\mathrm{Scale}\left(\mathrm{img},16,\mathrm{method}=\mathrm{nearest}\right):$
 > $\mathrm{gridFill}\left(\mathrm{img},16\right)$
 > $\mathrm{crossHair}\left(\mathrm{img},10.3,7.4,16\right)$
 > $\mathrm{crossHair}\left(\mathrm{img},4.8,1.9,16\right)$
 > $\mathrm{crossHair}\left(\mathrm{img},15.8,12.9,16\right)$
 > $\mathrm{Embed}\left(\mathrm{img}\right)$

The first solid circle above has the same coordinates and diameter as the first open circle, and hence has the same alignment and identical edge pixels. The second solid circle above has non-integer center coordinates and a non-even diameter, resulting in some edges that don't fall on pixel boundaries.

Write collage containing the previous four circles at original size. The following image shows each of the four circles above, rendered at their original size.

 > $\mathrm{Embed}\left(\mathrm{img4}\right)$

Compatibility

 • The ImageTools[Draw][Circle] and ImageTools[Draw][SolidCircle] commands were introduced in Maple 2018.