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);

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


has several examples


and the Index of Problem Coding Techniques 


has some (perhaps slightly different and slightly older) examples


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.


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.