WeBWorK Main Forum

Filled Disks

Filled Disks

by Andrew Dabrowski -
Number of replies: 3
What's the best way to make a filled disk in a graph? I haven't seen any documentation on shading regions, just on plotting curves.

For that matter, what's the best way to draw a circle? I've been using the kludge

 my $funstr = "sqrt($r^2 - (x - $x)^2) for x in [$a,$b]";
 my @circles = ("$y + " . $funstr,"$y - " . $funstr);
 add_functions($pic,@circles);

but that's kind of ugly. In fact the sqrt function doesn't play nice with graphs, as it sometimes returns values near 0 in scientific notation which it seems the graphing utilities can't understand.

In reply to Andrew Dabrowski

Re: Filled Disks

by Paul Pearson -
Hi Andrew,

Webwork, which uses GD to generate dynamic graphs, does have a "paint bucket" utility.  The graphing category on the Subject Area Templates wiki

http://webwork.maa.org/wiki/Category:Subject_Area_Templates

has several examples

http://webwork.maa.org/wiki/GraphShading1
http://webwork.maa.org/wiki/PolarGraph1
http://webwork.maa.org/wiki/ContourPlot1

and the Index of Problem Coding Techniques 

http://webwork.maa.org/wiki/Problem_Techniques

has some (perhaps slightly different and slightly older) examples

http://webwork.maa.org/wiki/DynamicImages3
http://webwork.maa.org/wiki/ContourPlots

The things I use most when writing webwork problems are usually found on the Subject Area Templates page, the Problem Techniques page, and in Davide Cervone's documentation.  Usually, google does a good job of finding what you want (e.g., google "webwork filled graph").

Best regards,

Paul Pearson


In reply to Andrew Dabrowski

Re: Filled Disks

by Alex Jordan -
You can also plot things parametrically. For example, here you will find an example of a sideways parabola.

https://github.com/openwebwork/webwork-open-problem-library/blob/master/Contrib/PCC/BasicAlgebra/FunctionBasics/FunctionOrNotByGraph20.pg

It was not plotted as two sqrt functions, but rather as a shifted polar form converted to Cartesian. You can adopt this to plot any x(t),y(t). For circles, this would be much simpler than parabolas.