Interactive graphing tool problem that asks the student to plot points.
Download file: GraphToolPoints.pg
DOCUMENT();
loadMacros('PGstandard.pl', 'PGML.pl', 'parserGraphTool.pl', 'PGcourse.pl');
Preamble
This example shows how to get student input in the form of points by using interactive graphing tools. Load the parserGraphTool.pl macro for this.
$x1 = non_zero_random(-5, 5);
$y1 = non_zero_random(-5, 5);
$x2 = non_zero_random(-5, 5);
$y2 = non_zero_random(-5, 5);
$gt = GraphTool("{point, ($x1, $y1)}", "{point, ($x2, $y2)}")->with(
availableTools => ['PointTool'],
bBox => [ -11, 11, 11, -11 ],
showCoordinateHints => 0,
);
Setup
Two points are created at random.
The GraphTool method creates the graph tool object. The
only argument is the correct answer. This is a string that contains a
list of objects that the student will be expected to graph. Each object
is a brace delimited list of the attributes of the object. The first
attribute in each list is the type of object to be graphed,
point in this case. What the remaining attributes are
depend on the type. For a point, there is only one additional attribute
which is the point itself.
The ->with method is then used to set options for the
GraphTool object. In this case the options that are set
are:
bBox: This is an array reference of four values
xmin, ymax, xmax, ymin indicating the upper left and lower
right corners of the visible graph.availableTools: This determines which tools will be
available for the student to use.showCoordinateHints: Setting this to 0 turns off
coordinate hints, which would show the coordinates of the point the
cursor is over.For more details, see the POD.
BEGIN_PGML
Graph the points [`([$x1], [$y1])`] and [`([$x2], [$y2])`].
[_]{$gt}
END_PGML
Statement
The code [_]{$gt} inserts the GraphTool.
BEGIN_PGML_SOLUTION Solution explanation goes here. END_PGML_SOLUTION ENDDOCUMENT();
Solution
A solution should be provided here.