Triangle Graph Tool

Shows a triangle tool within the GraphTool.

Complete Code

Download file: TriangleGraphTool.pg

POD for Macro Files

PG problem file

Explanation

DOCUMENT();

loadMacros('PGstandard.pl', 'PGML.pl', 'parserGraphTool.pl', 'PGcourse.pl');

Preamble

Load the parserGraphTool.pl macro to be able to use the GraphTool.

$x1 = random(-8, 8);
$y1 = random(-8, 8);
do { $x2 = random(-8, 8); $y2 = random(-8, 8) } until $x2 != $x1 || $y2 != $y1;
do { $x3 = random(-8, 8); $y3 = random(-8, 8) }
    until ($y3 - $y1) * ($x2 - $x1) != ($y2 - $y1) * ($x3 - $x1);

$gt = GraphTool("{ triangle, solid, ($x1, $y1), ($x2, $y2), ($x3, $y3) }")
    ->with(availableTools => [ 'TriangleTool', 'FillTool', 'SolidDashTool' ]);

Setup

This finds three unique random points and sets up the GraphTool. The line { triangle, solid, ($x1, $y1), ($x2, $y2), ($x3, $y3) } creates a triangle with solid line edges and the given three points.

BEGIN_PGML
Graph the triangle with vertices [`([$x1], [$y1])`], [`([$x2], [$y2])`], and
[`([$x3], [$y3])`].

[_]{$gt}
END_PGML

Statement

This asks the student to graph a triangle with the given vertices. The code [_]{$gt} inserts the graph tool.

BEGIN_PGML_SOLUTION
The correct answer is

[!A graph of the triangle with vertices ([$x1], [$y1]), ([$x2],[$y2]) and ([$x3],[$y3])!]{$gt}
END_PGML_SOLUTION

ENDDOCUMENT();

Solution

To show the graph with alternate text we use the PGML image construct [! !]{$gt}, where the alternate text is placed within the [! !].