|
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
|
|
•
|
lines are always tied to groups; if a line is specified outside of a group, then a group is created
|
•
|
use the Group element to combine other elements together with the lines
|
•
|
a matrix of (x,y) pairs can be used to draw shapes
|
|
|
Viewing Lines
|
|
•
|
create or fetch a canvas with lines in it, then view them in Maple
|
|
|
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)
|
>
|
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:
|
|
|
|
Compatibility
|
|
•
|
The DocumentTools[Canvas][Line] command was introduced in Maple 2022.
|
|
|
|