Communicating with Geogebra

162 views
Skip to first unread message

wha...@maritime.edu

unread,
Jun 29, 2018, 9:58:20 AM6/29/18
to Numbas Users
1. Can someone show me how to communicate with the Geogebra applet once it is loaded into a Numbas question?

For example, when I call numbasGGBApplet0.getValueString('R')  from the browser debugger it works, but when I use it in a question the whole question reloads. See https://wiki.geogebra.org/en/Reference:GeoGebra_Apps_API

2.  Also, I find that Numbas is not respecting the Geogebra Advanced Setting "Enable dragging of labels."


 

Christian Lawson-Perfect

unread,
Jul 5, 2018, 3:49:13 AM7/5/18
to numbas...@googlegroups.com
Hi,

1. If you're using the geogebra_applet JME function, you can't reliably get the applet: it only returns the HTML element that the applet will be attached to once it loads, and JME doesn't work asynchronously. However, the geogebra extension provides a JavaScript function Numbas.extensions.geogebra.createGeogebraApplet (documented at https://github.com/numbas/numbas-extension-geogebra#creategeogebraappletoptions), which returns a Promise that will resolve to give you both the container element and the GeoGebra applet object. It can take a while to get your head round promises, so I've made an example at https://numbas.mathcentre.ac.uk/question/35249/manipulate-a-geogebra-applet-in-javascript/. The extension could make this a bit easier - I'll have a look at that.

2. Numbas shouldn't be doing anything to affect that setting. Can you give an example?

--
You received this message because you are subscribed to the Google Groups "Numbas Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to numbas-users...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

wha...@maritime.edu

unread,
Jul 7, 2018, 6:42:16 PM7/7/18
to Numbas Users
Thanks for the info.  I've been reading the docs on promises but I'm still pretty confused. However, with your hint I can now talk to the applet using the Geogebra api, however what I really want to do is use values known to Geogebra as part of a marking algorithm.  

I feel like I should be able to say something like:

settings['expected_answer'] = numbasGGBApplet0.getValue('q1');

"before the built-in script" but I can't figure out how to make it work.  It would be really helpful if I could.  Is this possible?

Thanks,
Will

Christian Lawson-Perfect

unread,
Jul 10, 2018, 4:02:14 AM7/10/18
to numbas...@googlegroups.com
There are a lot of ways you can use information from a GeoGebra applet. If I had more informatino about what you're trying to do I could be more helpful.
I've made an example at https://numbas.mathcentre.ac.uk/question/35416/use-information-from-a-geogebra-applet-in-marking/ which checks for the existence of a point at a particular set of coordinates. It does this by keeping track of the objects that exist in the applet via a dictionary attached to the question object, which the marking script then uses.

wha...@maritime.edu

unread,
Jul 10, 2018, 7:13:32 PM7/10/18
to Numbas Users
Christian,

I teach engineering mechanics (statics) at Massachusetts Maritime Academy and also am a long time geogebra user.  I've made a lot of geogebra diagrams over the years, some of which are here https://ggbm.at/eKD1jLzg . I'm very excited about the possibilities of Numbas+geogebra for generating randomized mechanics problems and also for guided problem solving and exploration. I'm familiar with html, xml, xslt, css, LaTeX, mathJax, and ruby, but i'm a novice with javascript and have never used jquery.  I've only been exploring Numbas for about two weeks.

I have LOTS of ideas, but so far in my explorations I keep wanting check student answers against values which are already known by the geogebra applet.  For my problems these are not dynamic values;  - once Numbas loads GGB and passes in random values nothing more changes.


Students are asked to find the area and centroid of a random polygon; Numbas generates the four corners. I want them to consider the polygon as a large rectangle with some pieces removed, and fill in a table with the areas and coordinates of the centroids of these pieces.   Potentially there is a (blue) rectangle and two (red) triangles at each vertex of the (gray) polygon, but depending on the particular polygon, some of these collapse to nothing and are not considered.   

I want to query GGB to find out which sub-shape are zero and remove their corresponding rows from the table, and then use the areas and centroidal coordinates of the remaining shapes as the correct answers to the gaps in columns 1, 2 and 3.  It's possible to solve this problem analytically inside Numbas which I've done for part b, but it only works for shapes with straight sides, and it isn't the way I want the students to solve these types of problems.  

Maybe there could be a Numbas function which grabs GGB values and assigns them to JME variables?  Or a parameter on the geogebra_applet() function which maps selected geogebra values back to Numbas?  Or a custom part type which takes a GGB variable name as input and checks the student answer against the value of that variable?  I'm not familiar enough to know what's the best approach or how to implement it.

Thanks,

Will

wha...@maritime.edu

unread,
Jul 24, 2018, 10:38:16 AM7/24/18
to Numbas Users
I've been able to work out how to send commands to Geogebra and to use the values from the applet as the correct answers to Numbas gaps.



Christian Lawson-Perfect

unread,
Jul 25, 2018, 5:54:50 AM7/25/18
to numbas...@googlegroups.com
Glad you got something working! Sorry I haven't got round to replying sooner - busy time of year!
I can't see how that question fills in the gaps. Is there something I need to do inside the applet?

On Tue, 24 Jul 2018 at 15:38 <wha...@maritime.edu> wrote:
I've been able to work out how to send commands to Geogebra and to use the values from the applet as the correct answers to Numbas gaps.



wha...@maritime.edu

unread,
Jul 25, 2018, 4:06:06 PM7/25/18
to Numbas Users
I'm using a custom gap script which grabs the answer from GGB and stuffs it into the gap setting before marking the student's answer. 

this.settings.maxvalue = this.settings.minvalue = numbasGGBApplet0.getValue("x(centroid)");


Note that in my example I have left the points free, so you can drag them around and change the shape.  The gap answers are the coordinates of the centroid of the shape as it appears when you click submit.

By the way, I've just published 10 questions to the public database which I plan to assign to my students in the fall.  If you get a chance, please have a look at them.  I think they demonstrate some of the incredible possibilities of Numbas/Geogebra integration.  
Reply all
Reply to author
Forward
0 new messages