Line - Maple Help

# Online Help

###### All Products    Maple    MapleSim

ImageTools[Draw]

 Line
 ImageTools:-Draw Line Primitive

 Calling Sequence Line( image, x1, y1, x2, y2, color, thickness, round, pattern )

Parameters

 image - x1 - numeric y1 - numeric x2 - numeric y2 - numeric color - (optional) see description thickness - (optional) numeric := 1.0 round - (optional) truefalse := false pattern - (optional) identical("none", "solid", "dash", "dot", "dashdot", "dashdotdot") := "solid"

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 Line primitive draws a straight line between two specified points. The same result can be achieved using the Poly primitive with a list of two points, except that the line primitive also has the ability to draw tapered lines.
 • The x1, y1, x2, and y2 arguments give the coordinates of the end-points, (x1,y1) and (x2,y2).
 • 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 argument specifies the apparent thickness of the line, measured in pixels. Because of anti-aliasing, the number of pixels used to render the line at any point may be more than this, but the line will appear to be of the specified thickness.
 Instead of a single thickness, a list of two separate thicknesses for the start and end of the line can be specified, producing a tapered line
 • By default, the line ends exactly at the specified coordinates, and for a line with thickness noticeably larger than 1, the ends of the line will be perpendicular to the line itself. If the round argument is specified as true, then the line ends will be rounded, and the specified end-points will be the centers of those rounded ends, i.e., the line will extend by half its thickness in all directions from the end-points
 • The pattern argument can be used to draw lines with one of a fixed number of patterns. The default pattern, solid, draws solid lines. The other available patterns are:
 "dash"
 "dot"
 "dashdot"
 "dashdotdot"
 "none"
 • The options beginning with color are best provided as keyword equations, but can also be provided as positional arguments starting in the 6th position as declared in the calling sequence above.

Package Usage

 • This function is part of the ImageTools:-Draw package, so it can be used in the short form Line(..) 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:-Line(..).

Examples

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

Lines of different thicknesses.

 > $\mathrm{img}≔\mathrm{Create}\left(240,320,\mathrm{channels}=3,\mathrm{background}=\mathrm{white}\right):$
 > $\mathrm{Line}\left(\mathrm{img},32,32,288,144,\mathrm{color}=0.25,\mathrm{thickness}=0.5\right)$
 > $\mathrm{Line}\left(\mathrm{img},32,64,288,176,\mathrm{color}=0.25,\mathrm{thickness}=1\right)$
 > $\mathrm{Line}\left(\mathrm{img},32,96,288,208,\mathrm{color}=0.25,\mathrm{thickness}=3\right)$
 > $\mathrm{Embed}\left(\mathrm{img}\right)$

Tapered lines.

 > $\mathrm{img}≔\mathrm{Create}\left(240,320,\mathrm{channels}=3,\mathrm{background}=\mathrm{white}\right):$
 > $\mathrm{Line}\left(\mathrm{img},32,32,288,144,\mathrm{color}=0.25,\mathrm{thickness}=\left[0.5,5\right]\right)$
 > $\mathrm{Line}\left(\mathrm{img},32,96,288,208,\mathrm{color}=0.25,\mathrm{thickness}=\left[15,5\right]\right)$
 > $\mathrm{Embed}\left(\mathrm{img}\right)$

Round vs. square line ends.

 > $\mathrm{img}≔\mathrm{Create}\left(240,320,\mathrm{channels}=3,\mathrm{background}=\mathrm{white}\right):$
 > $\mathrm{Line}\left(\mathrm{img},32,32,288,144,\mathrm{color}=0.25,\mathrm{thickness}=10,\mathrm{round}=\mathrm{true}\right)$
 > $\mathrm{Line}\left(\mathrm{img},32,96,288,208,\mathrm{color}=0.25,\mathrm{thickness}=10,\mathrm{round}=\mathrm{false}\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:

Zoomed image of anti-aliased line with integer endpoints.

 > $\mathrm{img}≔\mathrm{Create}\left(15,20,\mathrm{channels}=3,\mathrm{background}=\mathrm{white}\right):$
 > $\mathrm{Line}\left(\mathrm{img},2,2,18,13,\mathrm{color}=0\right)$
 > $\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},2,2,16\right)$
 > $\mathrm{crossHair}\left(\mathrm{img},18,13,16\right)$
 > $\mathrm{Embed}\left(\mathrm{img}\right)$

Zoomed image of anti-aliased line with non-integer endpoints.

 > $\mathrm{img}≔\mathrm{Create}\left(15,20,\mathrm{channels}=3,\mathrm{background}=\mathrm{white}\right):$
 > $\mathrm{Line}\left(\mathrm{img},2.5,2.5,17.5,12.5,\mathrm{color}=0\right)$
 > $\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},2.5,2.5,16\right)$
 > $\mathrm{crossHair}\left(\mathrm{img},17.5,12.5,16\right)$
 > $\mathrm{Embed}\left(\mathrm{img}\right)$

Line pattern examples.

 > $\mathrm{img}≔\mathrm{Create}\left(260,320,\mathrm{channels}=3,\mathrm{background}=\mathrm{white}\right):$
 > $\mathrm{Line}\left(\mathrm{img},32,32,288,144,\mathrm{pattern}="dash"\right)$
 > $\mathrm{Line}\left(\mathrm{img},32,64,288,176,\mathrm{pattern}="dot"\right)$
 > $\mathrm{Line}\left(\mathrm{img},32,96,288,208,\mathrm{pattern}="dashdot"\right)$
 > $\mathrm{Line}\left(\mathrm{img},32,128,288,240,\mathrm{pattern}="dashdotdot"\right)$
 > $\mathrm{Embed}\left(\mathrm{img}\right)$

Compatibility

 • The ImageTools[Draw][Line] command was introduced in Maple 2018.
 • For more information on Maple 2018 changes, see Updates in Maple 2018.

 See Also