Line - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

DocumentTools[Canvas]

 Line
 create a line drawing overlay on a canvas

 Calling Sequence Line(points) Line(points, options )

Parameters

 points - list or rtable color=string - (optional) default is "black" thickness=posint - (optional) line thickness alpha=0..255 - (optional) transparency position=[posint,posint] - (optional) absolute position of the group containing the line

Description

 • The Line command creates a drawing overlay anchored to a group in a canvas.  This is what gets constructed when using the pen tool in Maple Learn.  These lines are part of the canvas structure and are visible in Maple Learn, but are not shown by the ShowCanvas command.
 • The input should be a Mx2 matrix or list of (x,y) pairs.  The (0,0) position is the top left corner of the group, including the gutter of the group.  The x-coordinate increases as you draw right, and the y-coordinate increases as you draw down.  Both are in pixels.
 • The line color can be specified using the option color=string.  The default color is "black".  Color values can be named, as in "yellow", "blue", "red", and "green, or RGB values, where "#FF0000" is red.
 • The thickness=N option controls the line thickness.  N must be a positive integer.
 • The alpha=A option controls the opacity.  A value of A=0 will set the line to completely transparent (invisible), and A=255 will be completely opaque.  A value of A=100 will allow text and math behind the line to show through while the line is still visible.
 • The GetMath command can be used with the keep={"line"} option to extract lines from a canvas.  Each line element is a record data structure.
 The data member of the record contains a matrix of points, that, when connected, form the line.
 Use the convertToPlotData member of the record to convert the point values into approximate plot coordinates for a StaticPlot structure appearing as the first element of the group.  The convertToPlotData member can be given a view=[xmin..xmax,ymin..ymax] option to scale the coordinates into the appropriate view.  The convertToPlotData member can be given an offset=N option to adjust the lines by N pixels from the top of the group (to allow positioning the blank StaticPlot as the second or other line in the group).
 Use the plot member of the record to display individual lines as a Maple plot.

Examples

Creating Lines

 > $\mathrm{with}\left(\mathrm{DocumentTools}:-\mathrm{Canvas}\right):$
 • lines are always tied to groups; if a line is specified outside of a group, then a group is created
 > $\mathrm{cv}≔\mathrm{NewCanvas}\left(\left["Line",{x}^{2},\mathrm{Line}\left(\left[\left[30,40\right],\left[400,40\right]\right]\right),{y}^{2}\right]\right):$
 > $\mathrm{ShareCanvas}\left(\mathrm{cv}\right)$
 • use the Group element to combine other elements together with the lines
 > $\mathrm{cv}≔\mathrm{NewCanvas}\left(\left["Line",\mathrm{Group}\left(\left[{x}^{2},\mathrm{Line}\left(\left[\left[30,40\right],\left[400,40\right]\right]\right),{y}^{2}\right]\right)\right]\right):$
 > $\mathrm{ShareCanvas}\left(\mathrm{cv}\right)$
 • a matrix of (x,y) pairs can be used to draw shapes
 > $\mathrm{cv}≔\mathrm{NewCanvas}\left(\left["Line",\mathrm{Group}\left(\left[{x}^{2},\mathrm{Line}\left(⟨⟨55|0⟩,⟨55|40⟩,⟨90|40⟩,⟨90|0⟩,⟨55|0⟩⟩\right),{y}^{2}\right]\right)\right]\right):$
 > $\mathrm{ShareCanvas}\left(\mathrm{cv}\right)$

Viewing Lines

 > $\mathrm{with}\left(\mathrm{DocumentTools}:-\mathrm{Canvas}\right):$
 • create or fetch a canvas with lines in it, then view them in Maple
 > $\mathrm{cv}≔\mathrm{NewCanvas}\left(\left["Line",\mathrm{Group}\left(\left[{x}^{2},\mathrm{Line}\left(⟨⟨55|0⟩,⟨55|40⟩,⟨90|40⟩,⟨90|0⟩,⟨55|0⟩⟩,\mathrm{color}="#FF0000"\right),\mathrm{Line}\left(⟨⟨55|10⟩,⟨90|10⟩⟩,\mathrm{thickness}=20,\mathrm{\alpha }=255,\mathrm{color}="yellow"\right),{y}^{2}\right]\right)\right]\right):$
 > $M≔\mathrm{GetElements}\left(\mathrm{cv},"line"\right):$$\mathrm{numelems}\left(M\right)$
 > $\mathrm{plots}:-\mathrm{display}\left(\mathrm{seq}\left(\mathrm{elem}:-\mathrm{plot}\left(\mathrm{elem},\mathrm{view}=\left[-10..10,-10..10\right]\right),\mathrm{elem}=M\right)\right)$

Draw on Plot

 • In this section we create an app that allows you to draw on a blank plot, then do a curve fit of the sketch Note: drawing is done using the Pen tool in Maple Learn.  The Pen tool had not been released in the Production version of Maple Learn at the time of writing this example (hopefully it will be there when you try this)
 > $\mathrm{with}\left(\mathrm{DocumentTools}:-\mathrm{Canvas}\right):$
 > Fit := proc( canvas )    local M := GetElements(canvas,"line"):    local sc := Script();    SetActive(sc,"3:0");    if numelems(M) =  0 then        SetText(sc,"No lines were drawn");    elif numelems(M) > 1 then        SetText(sc,"Multiple lines were drawn, clear your drawing and try again with just one smooth curve");    else        local data := M[1]:-convertToPlotData( M[1], offset=0, view=[-10..10,-10..10] );        local f, a1, b1, c1, d1;        f := CurveFitting:-LeastSquares( data, x, 'curve' = a1+b1*x+c1*x^2+d1*x^3 );        SetText(sc,"Your curve looks like: ");        SetMath(sc,f,'where'="below");        SetActive(sc,"1:0");        SetPlot(sc,plot(f,view=[-10..10,-10..10]));    end if;    ToString(sc); end proc:
 > $\mathrm{cv}≔\mathrm{NewCanvas}\left(\left["Sketch:",\mathrm{StaticPlot}\left(\right),\mathrm{ScriptButton}\left("Apply LeastSquares Fit",\mathrm{Fit},\mathrm{position}=\left[570,92\right]\right),\mathrm{Group}\left(\left[\mathrm{Text}\left("Draw a line on the plot area using the pen tool then click the button above"\right)\right],\mathrm{position}=\left[550,132\right]\right)\right]\right):$
 > $\mathrm{ShareCanvas}\left(\mathrm{cv}\right)$

Compatibility

 • The DocumentTools[Canvas][Line] command was introduced in Maple 2022.
 • For more information on Maple 2022 changes, see Updates in Maple 2022.