Difference between revisions of "GeoGebraApplets"
Line 4: | Line 4: | ||
<p style="background-color:#eeeeee;border:black solid 1px;padding:3px;"> |
<p style="background-color:#eeeeee;border:black solid 1px;padding:3px;"> |
||
− | <em>This PG code shows how to write WebWork questions with interactive [http://www.geogebra.org/ GeoGebra] applets.</em> |
+ | <em>This PG code shows how to write WebWork questions with interactive [http://www.geogebra.org/ GeoGebra] applets. Instructions for how to create the interactive applet in GeoGebra are given at the bottom of the page.</em> |
</p> |
</p> |
||
Line 368: | Line 368: | ||
[[Category:Problem Techniques]] |
[[Category:Problem Techniques]] |
||
+ | |||
+ | |||
Line 373: | Line 375: | ||
<tr> |
<tr> |
||
<td style="background-color:#ddffdd;border:black 1px dashed;"> |
<td style="background-color:#ddffdd;border:black 1px dashed;"> |
||
+ | <h3><u>The really long parameter ggbBase64</u></h3> |
||
<param name="ggbBase64" value="UEsDBBQACAAIAGKtZj0AAAAAAAAAAAAAAAAMAAAAZ2VvZ2VicmEueG1s3Vdtb9s2EP68/gqCAwobQ2xKll1ntVJk2QYE6NYA2YpgHwbQ0tnmIokeSTlyfv2OpCTLypIm64C9+INlHk/Hu+c5PqQX76o8IztQWsgipsGIUQJFIlNRrGNamtXJnL47e7VYg1zDUnGykirnJqaTUUitvRRnr75Y6I28IzxzLh8F3MV0xTMNlOitAp7qDYA5svOyEpngav9h+RskRh8mfJDLYlviKkaVaEvy9L3QzXDsFtxmwnwrdiIFRTKZxHQ2xdTx10dQRiQ8i2nEvCWMadibRNPEzm6kEveyMNb9EDzjS8gQgGuzz4CQnZ0N/dQKnQnR4h4QLGdbjB0GCyiTTKSCF7ZOlyI6EXInUrPBXOYzXA3EemOxY5GPlkip0uu9NpCT6hdQEoPOLAV7PwhDR4jGjHG9KXNT3ZGLArtrMAbz1YRXoBvU1kqk3d+X+huZpS3QWykKc8G3plSOa1abXNFuqGy258U6g9oWIBUbSG6Xsrr2CEx86J/2W/eKS2e5vpCZVERZ2KfoUD+X/ul8bJ6tF3M+zHnUMWz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0kodWAxrkZGma8CufVJ3KAzZWTVItsvRYZ8wGN3QBWtsDoS38IT9HmvBCetgz6WF9EXw0ucdZuLKK36OgOkeJe4DczdPIuaOjrfiGPo3IQU67gDSnxUsh+bBaaTCksvS/wQPSnvx/ilj4+Q1d66W2q6Fv6JZzPXfvX3Y+/iC1579bd/o0CZeFQaHmWY+H1aCqu7rt6WpwM3zADH+amb7C8L7CsNEpY2waTcJoPg/nUzb7rIYOppP2rD8wOHmZ5rywqaHCa6a2V9i2w6AyyCpOxPT176U0by8Px5j++vWXAXt7kWFoYnlIFV/jSkAU4EAirpksvOVwQyTmxB7+Ix/OpXCMtF2THifwTwrDSlRYze74auvurxobYnW4orurHIKrm4uKp99wZZw+kLrZp6fdz9zvtBGbse5n2t0Jn+YoPOLoWqwLzJnjfwYSE29DreeUPAPt8D+EdtSizR5DOzyC1QvNSTCKor79JXBHR3DvEeTdwAyf39HRXxL2fyXE0xHzLRyMZtFjKI67t1/3X6/+H3z2B1BLBwh3r/gKdQQAADkPAABQSwECFAAUAAgACABirWY9d6/4CnUEAAA5DwAADAAAAAAAAAAAAAAAAAAAAAAAZ2VvZ2VicmEueG1sUEsFBgAAAAABAAEAOgAAAK8EAAAAAA=="/> |
||
</td> |
</td> |
||
</tr> |
</tr> |
||
</table> |
</table> |
||
+ | |||
+ | |||
Line 384: | Line 389: | ||
<h3><u>Steps to construct the GeoGebra applet:</u></h3> |
<h3><u>Steps to construct the GeoGebra applet:</u></h3> |
||
<ol> |
<ol> |
||
− | <li>Download [ |
+ | <li>Download [http://www.geogebra.org/cms/en/download GeoGebra], install it, and run it.</li> |
<li>From the menu bar at the top of GeoGebra, select <code>View -> Grid</code></li> |
<li>From the menu bar at the top of GeoGebra, select <code>View -> Grid</code></li> |
||
<li>In the Input textbox at the bottom of GeoGebra, type <code>c=1 (Enter)</code> and <code>d=3 (Enter)</code> to create Free Objects</li> |
<li>In the Input textbox at the bottom of GeoGebra, type <code>c=1 (Enter)</code> and <code>d=3 (Enter)</code> to create Free Objects</li> |
||
Line 413: | Line 418: | ||
</tr> |
</tr> |
||
</table> |
</table> |
||
+ | |||
+ | |||
+ | |||
<ul> |
<ul> |
Revision as of 14:32, 7 November 2010
GeoGebra Applets
This PG code shows how to write WebWork questions with interactive GeoGebra applets. Instructions for how to create the interactive applet in GeoGebra are given at the bottom of the page.
PG problem file | Explanation |
---|---|
DOCUMENT(); loadMacros( "PGstandard.pl", "MathObjects.pl", "unionTables.pl", "AppletObjects.pl", "parserNumberWithUnits.pl", "PGcourse.pl", ); $showPartialCorrectAnswers = 1; TEXT(beginproblem()); |
Initialization:
We need to include the macro file |
Context("Numeric")->variables->are(t=>"Real"); $a = random(2,4,1); $b = random(5,8,1); $c = random(1,3,1); $d = random(1,3,1); while ($c == $d) { $d = random(1,3,1); } # $f = Formula("$c / (1+(t-2)^2) + $d / (1+(t-4)^2)"); $F = Formula("$c * arctan(t-2) + $d * arctan(t-4) - $c * arctan(-2) - $d * arctan(-4)"); $Fa = $F->eval(t=>$a); $Fb = $F->eval(t=>$b); $disp = $Fb-$Fa; |
Setup:
The GeoGebra applet displays a graph of
We define the accumulation function (antiderivative) |
$appletName = "ggbApplet"; $applet = JavaApplet( code => "geogebra.GeoGebraApplet", archive => "geogebra.jar", codebase => findAppletCodebase("geogebra.jar"), appletName => $appletName, appletId => $appletName, submitActionAlias => 'getXML', # default getXML initializeActionAlias => 'setXML', # default setXML setStateAlias => 'setXML', getStateAlias => 'getXML', setConfigAlias => '', getConfigAlias => '', returnFieldName => '', width => 486, height => 306, mayscript => "true", # 0 = no debug, 1 = xml visible, 2 = add alerts thru applet debugMode => 0, onInit => 'ggbOnInit', type => 'geogebra', # paste parameters in section at the bottom parameter_string => GEOGEBRA_PARAMS(), ); |
GeoGebra Applet Setup:
We use
Since the GeoGebra parameters can be very lengthy, at the end of the PG file we put a new
method called |
$im = image( "graph-c".$c."-d".$d.".png", width=>486, height=>306, tex_size=>900 ); |
PNG Picture Setup:
For each of the six ordered pairs |
HEADER_TEXT( qq! <script language="javascript"> function ggbOnInit(param) { if (param == "$appletName") { applet_loaded(param,1); // report that applet is ready. ww_applet_list[param].safe_applet_initialize(2); } } </script> <noscript>For this question to work properly, you must enable JavaScript, or use another browser (or computer) on which JavaScript works.</noscript> !); |
JavaScript Setup for Persistence of State: For the state of the GeoGebra applet to remain the same when answers are submitted or the page is refreshed, we need a little JavaScript. GeoGebra can interact with other things, like WebWork, by using its JavaScript methods GeoGebra_JavaScript_Methods. |
TEXT( MODES(TeX=>'', HTML=><<END_SCRIPT ) ); <script language="javascript"> function setAppletCoefficients() { var applet=getApplet("$appletName"); // alert("Updating coefficients"); if (typeof(applet)!="undefined") { if (typeof(applet.setValue)!="undefined") { //////////////////////////////////////////////////////////////// // List the values of the parameters to be set in the applet here // Set variables "c" and "d" in GeoGebra to values $c and $d from WebWork applet.setValue("c", $c); applet.setValue("d", $d); } else { setTimeout("setAppletCoefficients()", 1000); } } else { setTimeout("setAppletCoefficients()",1000); } } ww_applet_list["$appletName"].setConfig = function() {setAppletCoefficients()}; </script> END_SCRIPT |
JavaScript Setup for Initial State:
We use JavaScript methods to set the values of the
variables |
Context()->texStrings; BEGIN_TEXT \{ ColumnTable( "The figure shows an interactive graph of velocity \( v(t) \), in meters per second, where time \( t \) is measured in seconds. You can change the value of \( t \) in the graph by clicking and dragging the red dot along the horizontal \( t \)-axis. $BR $BR (a) What is the displacement between \( t = 0 \) seconds and \( t = $a \) seconds? $BR". ans_rule(20). " (include ".helpLink('units').") $BR $BR (b) What is the displacement between \( t = 0 \) seconds and \( t = $b \) seconds? $BR". ans_rule(20). " (include ".helpLink('units').") $BR $BR (c) What is the displacement between \( t = $a \) seconds and \( t = $b \) seconds? $BR". ans_rule(20). " (include ".helpLink('units').")" , $BCENTER. MODES(HTML=>$applet->insertAll(debug=>0, reinitialize_button=>0, includeAnswerBox=>0,), TeX=>$im). $PAR. "Graph of velocity \( y = v(t) \)". $ECENTER , indent => 0, separation => 30, valign => "TOP" ); \} END_TEXT Context()->normalStrings; |
Main Text:
The problem text section of the file is mostly as we'd expect.
We make use of a |
ANS( NumberWithUnits("$Fa","m") ->cmp(tolerance=>0.11, tolType=>'absolute') ); ANS( NumberWithUnits("$Fb","m") ->cmp(tolerance=>0.11, tolType=>'absolute') ); ANS( NumberWithUnits("$disp","m")->cmp(tolerance=>0.21, tolType=>'absolute') ); |
Answer Evaluation: Standard. |
sub GEOGEBRA_PARAMS { $result = qq{ # For persistence of applet state when answers are submitted <param name="ggbOnInitParam" value="$appletName"/> # The GeoGebra "source code" from GeoGebra -> # File -> Export -> Dynamic worksheet as Webpage (html) <param name="ggbBase64" value="UEsDBBQ....stuff omitted..."/> <param name="image" value="http://www.geogebra.org/webstart/loading.gif" /> <param name="boxborder" value="false" /> <param name="centerimage" value="true" /> <param name="java_arguments" value="-Xmx512m" /> <param name="cache_archive" value="geogebra.jar, geogebra_main.jar, geogebra_gui.jar, geogebra_cas.jar, geogebra_export.jar, geogebra_properties.jar" /> <param name="cache_version" value="3.2.41.0, 3.2.41.0, 3.2.41.0, 3.2.41.0, 3.2.41.0, 3.2.41.0" /> <param name="framePossible" value="false" /> <param name="showResetIcon" value="false" /> <param name="showAnimationButton" value="true" /> <param name="enableRightClick" value="false" /> <param name="errorDialogsActive" value="true" /> <param name="enableLabelDrags" value="false" /> <param name="showMenuBar" value="false" /> <param name="showToolBar" value="false" /> <param name="showToolBarHelp" value="false" /> <param name="showAlgebraInput" value="false" /> <param name="allowRescaling" value="true" /> }; } COMMENT('MathObject version. Uses GeoGebra applet.'); ENDDOCUMENT(); |
GeoGebra Applet Parameters:
When you export your GeoGebra drawing pad via File -> Export -> Dynamic worksheet as Webpage (html), you get an html file with source code you can paste directly in here below the commented lines |
The really long parameter ggbBase64<param name="ggbBase64" value="UEsDBBQACAAIAGKtZj0AAAAAAAAAAAAAAAAMAAAAZ2VvZ2VicmEueG1s3Vdtb9s2EP68/gqCAwobQ2xKll1ntVJk2QYE6NYA2YpgHwbQ0tnmIokeS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v6JZzPXfvX3Y+/iC1579bd/o0CZeFQaHmWY+H1aCqu7rt6WpwM3zADH+amb7C8L7CsNEpY2waTcJoPg/nUzb7rIYOppP2rD8wOHmZ5rywqaHCa6a2V9i2w6AyyCpOxPT176U0by8Px5j++vWXAXt7kWFoYnlIFV/jSkAU4EAirpksvOVwQyTmxB7+Ix/OpXCMtF2THifwTwrDSlRYze74auvurxobYnW4orurHIKrm4uKp99wZZw+kLrZp6fdz9zvtBGbse5n2t0Jn+YoPOLoWqwLzJnjfwYSE29DreeUPAPt8D+EdtSizR5DOzyC1QvNSTCKor79JXBHR3DvEeTdwAyf39HRXxL2fyXE0xHzLRyMZtFjKI67t1/3X6/+H3z2B1BLBwh3r/gKdQQAADkPAABQSwECFAAUAAgACABirWY9d6/4CnUEAAA5DwAADAAAAAAAAAAAAAAAAAAAAAAAZ2VvZ2VicmEueG1sUEsFBgAAAAABAAEAOgAAAK8EAAAAAA=="/> |
Steps to construct the GeoGebra applet:
|
- POD documentation: AppletObjects.pl.html
- PG macro: AppletObjects.pl