## WeBWorK Problems

### dotted lines ### dotted lines

by Bruce Yoshiwara -
Number of replies: 8

Is it possible to create graphs using dashed or dotted lines? (The context is graphing inequalities in two variables, strict vs non-strict inequalities.) ### Re: dotted lines

by Gavin LaRose -
Hi Bruce,

I don't think this is supported by default (though perhaps someone will correct me on that). You can easily improvise something with the moveTo and lineTo methods of the graph object (c.f., http://webwork.maa.org/wiki/DynamicImages2).

Gavin ### Re: dotted lines

by Michael Gage -
Gavin has now modified the code in WWPlot.pm so that it supports dashed lines. See how to use the latest version at http://webwork.maa.org/wiki/DynamicImages2

This requires an up-to-date version of the pg files (greater than 2-4).

-- Mike ### Re: dotted lines

by Sean Fitzpatrick -

Resurrecting a very old thread, but I'm unsure how to do this for a function (the examples show how to do it for a line).

E.g. for

add_functions($gr, "4-3*e^(-x) for x in <-1,4> " . "using color:blue and weight:2"); is there a way to use dashed lines to plot the function? The context here is a WeBWorK problem in a PreTeXt book: I've got a few dynamic graphs with two functions. These are plotted as red and blue. For both accessibility and print-on-demand (where red and blue both print to grey) I would like one of the graphs to be dashed or dotted. In reply to Sean Fitzpatrick ### Re: dotted lines by Alex Jordan - add_functions() is defined at: https://github.com/openwebwork/pg/blob/master/macros/PGgraphmacros.pl#L346 It uses Fun.pm (https://github.com/openwebwork/pg/blob/master/lib/Fun.pm) to plot the function. And Fun.pm in turn relies on the GD package. I see nothing in Fun.pm that would help plot a function as dashed. So I think this would involve studying Fun.pm, and seeing if there is the right tool in GD that would allow Fun.pm to draw a dashed curve. And then editing Fun.pm to make use of that, and then also editing PGgraphmacros.pl so that a drawing style could be assigned by the problem author and be understood as an option to pass. Sorry it is not better news. But it may not be that large of a project to make it happen. Just know that if you modify Fun.pm, you must restart apache before testing. In reply to Alex Jordan ### Re: dotted lines by Sean Fitzpatrick - Rats. I'm not sure I trust myself to edit the Perl code. I'm considering just changing the colours from blue/red to black/grey. The other option would be to hand-edit the LaTeX file for print-on-demand to replace the WeBWorK images with the original TikZ code. In reply to Sean Fitzpatrick ### Re: dotted lines by Glenn Rice - There is a way to do this without modifying (or even using) Fun.pm. Here is an example of plotting a dashed parabola.$graph_image = init_graph(-11, -11, 11, 11, axes => [0, 0], grid => [22, 22], size => [300, 300]);

$x_rule = sub { return shift; };$y_rule = sub { my $x = shift; return 3 * ($x - 4) ** 2 + 2; };

$stepsize = 22 / 50;$graph_image->im->setStyle(($graph_image->{colors}{blue}) x 16, (GD::gdTransparent) x 16);$graph_image->moveTo(&$x_rule(0), &$y_rule(0));
for my $i (0 .. 50) { my$t = $stepsize *$i;
$graph_image->lineTo(&$x_rule($t), &$y_rule($t), GD::gdStyled, 2); }$graph = image(insertGraph($graph_image), width => 300, height => 300, tex_size => 1000); In reply to Glenn Rice ### Re: dotted lines by Alex Jordan - If I understand right, the dashes would have uniform length once projected to the x-axis, but not uniform length. For example a curve with a very steep section might appear to be plotted solid.$xrule(t) and \$yrule(t) could parametrize the curve by arc length. You might have to solve a calculus problem each time you do that, but if it's only four problems in APEX that are of concern here, that's more of a fun diversion than a tedious burden. 