Sum of area of all polygons

asbkon shared this question 3 months ago
Answered

Hello, I am wondering if there is possible to get the sum of the area of all polygons in one file. I have a file where my students can create a lot triangles and rectangles by custom tools. I want the geogebrafile to check whether the total area of the polygons in the file are a spesific number.

I appreciate if anyone has a solution to my problem.

Comments (10)

photo
1

you can count the sum of polygons by a simple sum. You can put all polygons in a file in one list l1 and the calculate Sum(l1) to get the sum of all polygons. But there's no command that will count automaticly all areas for you

chris

photo
1

I want the sum to be counted automatically. For example by a script. The polygons automatically gets named q1, q2, q3, etc. and the triangles t1, t2, t3 etc. I thought I could write a script that sum over say ten quadliterals and ten triangles but the script don't accept variables that is not defined yet.

So this is impossible to do? Or is there anyway I can get the file to overlook error messages for variables that is not defined (yet).

photo
photo
1

Or just sum the areas manually, e.g. if you have a triangle t1, a quadrilateral q1, and a circle p enter:


total=t1 +q1 +Area(p)


The Area() command is needed to calculate the area of a conic

photo
1

You can use commands for not yet defined objects since you knwo how they will be named: t1, ... or in general tn. In an Execute command you can use a counter n as variable and mix this variable with absolute text, append the new obect to a list of objects and make the sum of the lists. But this requires the objects to be created by eg a button that contains this script.

If you just freely create an object, this will not be part of a list, the category of triangles, etc is not a list as such.

photo
1

quizás el adjunto te sea util pues en la lista quedan reflejados todos los triangulos y sus nombres lo que permite seleccionar cuales objetos queremos sumar

el archivo tiene un grave problema con la version 5 pues además de que no funciona en absoluto se produce un fallo general que no permite construir nada

veré qué se puede hacer con este bug

photo
1

Thanks for trying to help. I am not sure I understood your comments.

@ccambre: Your solution seems great. Can you give an example of how the execute command would look like.


I am trying to reformulate my problem in the first place:

I have a file with a simple figure like this one in the attachement. I want my students to open the file and make polygons (inside my polygon) to "shade" the original polygon in a way that half of the polygons area is shaded. One possible to way is to define a lot of small clickable squares. Then the student can click on the small squares and by a script the squares can be shaded when clicking. But I want to give my students the opportunity to shade in more interesting ways, perhaps by shading triangles also. I also want the opportunity of using one, two, three, or another number of shaded parts. Therefore I want a way that the program automatically can calculate the area of shaded polygons (the polygons the students make) and then check whether or not this is half the original polygon.

photo
1

a possible solution

The fact that triangles and squares are named with the prefix t or q and a sequence number is used. The list of the two polygon types is determined automatically (even if there are gaps in the sequence number or the sequence number does not begin with 1 (e.g. by deletion)).

Note: t0 and q0 are dummy polygons with value 0 because the first element of the sequence can't be undefined.

photo
1

Thanks, a lot :) This is great!

The command RemoveUndefined was new to mee, but thats a brilliant command. That one solved everything.

photo
photo
1

si no funcionase por favor avise

simplemente cree varios triangulos

https://www.geogebra.org/m/yjgzsxwv

photo
1

here attached an example:

clic on t1, t2

© 2020 International GeoGebra Institute