Adding new dependent point to list of points without creating a new list (losing my mind on this)

amvukovic shared this question 1 week ago
Answered

First of all I want to apologize for starting New Topic on the actually old issue, but I didn't find the solution to my problem within this forum conversation (https://help.geogebra.org/t...) ...


So, I've found several suggestions regarding adding elements to existing list without creating a new one but none of these work with dependent objects and that's my problem...


I have an initial list named list1 which consists of one free point D, defined as:


  1. list1={D}

and three free points A, B and C.


Using Repeat and Execute commands I'm trying to repeat this procedure:

1.) generate random number r (random between 1 and 3)

2.) create point X as a midpoint of the segment which starts with point A, B or C as a one endpoint (A if r == 1, B if r == 2 ...) and the last point in the list1 as a second endpoint (at first, the second endpoint is point D)

3.) append point X to the list1 --> THIS IS WHERE MY PROBLEM STARTS...

4.) repeat the procedure given number of times


I've tried several approaches that work fine otherwise, like:


  1. list1=Append(CopyFreeObject(list1), X)

and


  1. SetValue(list1,Length(list1)+1,X)

but none of these work because point X isn't a free object (I suppose that's the biggest issue) and I always get either "circular definition" error (if I use first approach) or syntax error meaning that the command argument I'm using, that is list1, isn't a valid one (in the second approach).


You can see why I need to append point X to the existing list1, without creating a new one, because the second segment's endpoint is the last one in the list1. So, when the point X is created it should be pushed into list1 (at the last position) and it becomes the last point that is the second segment's endpoint in the new repetition of the procedure...


I'm honestly losing my mind on this and any help or suggestion would be more than appreciated!


Best regards


Aleksandra-Maria Vuković


Here is the procedure code (that will be repeated with the Repeat command):


  1. Execute( {"r=RandomBetween(1,3)","X=If(r==1,Midpoint(A,Element(list1, Length(list1))),If(r==2,Midpoint(B,Element(list1, Length(list1))),Midpoint(C,Element(list1, Length(list1)))))"} )

Now I need to push that point X to the last position of the list1, without creating a new one...

Comments (9)

photo
2

Hi,

I use

SetValue[list1,Append[list1,X]]

with list1={} (free list)

...clic on "reset" button, then list1={A,B,C,D}

see définition of X,

clic on "step" button, and see script...

So, list1={A,B,C,D,X}

...

photo
1

Hi,

error1 :


  1. list1=Append(CopyFreeObject(list1), X)

---> "circular definition" error

normal : in this définition of list1 you use list1 (impossible !)


error2 :


  1. SetValue(list1,Length(list1)+1,X)

---> syntax error

normal : SetValue( <Object>, <Object> ) work with free object :

first object take VALUE of second object (same type, or impossible !).

Here, you want list1 (a list) to take VALUE of second object Length(list1)+1 (a number) or X (a point) !?

...

Do not mix value and command...

...

And sorry for my very poor English.


photo
1

Dear Patrick, thanks for your quick reply - I will look at your solution as soon as I answer you ;-)

There isn't error1 (as you have named it) because I've used copy of the list1 with CopyFreeObject command and not the list1 itself and I've honestly created "kilometers" of GeoGebra materials and applets (figuratively speaking) using exactly that syntax! That's absolutely normal way to redefine var in any programming language...

The "circular definition" error occurs only when I use this way of list1 redefinition within Execute command... When I use it directly in input bar or within JavaScript code, there's no problem... But I would like to solve this with GGB scripting only... because I usually turn to JS scripting whenever something looks too complicated and this time I've decided to solve this only "inside" GeoGebra ;-)

Once again, thanks for your quick reply and I honestly hope this will be end to my misery ;-)

Alex

photo
photo
1

Dear Patrick, it seems that we have differently defined the list1 and that was the main issue! Dear Lord it would never occur to me...


The code

  1. SetValue[list1,Append[list1,X]]

didn't work in my applet with no point, no matter free of dependent and did in yours so I've asked myself what the heck???


I've initially defined the list1 as:

  1. list1={D}

instead of:

  1. list1={}

as you did and couldn't add any new point on your way!

photo
1

Hi,


ok,

it's not my matter, try and good luck...

photo
photo
2

A nice Sierpinski solution!

The desired solution with another approach (IterationList, no script).


  1. L_1 = IterationList(Midpoint(RandomElement({A, B, C}), last), last, {Midpoint(A, B)}, 4000)

Instead "D" I use "Midpoint(A,B)"

photo
1

Dear rami, I was in both regular work and GeoGebra as well almost whole day yesterday so I didn't see your answer!


Thanks and now I'm going to try the IterationList command <3


Once again thanks for your quick reply!


Alex

photo
photo
2

And one possibility with script (need a lot time!!)

Important: using RunClickScript() inside from Repeat() (Alternative: Execute)

photo
1

Thanks! I've come to the same solution based on your suggestion in the previous reply - with the IterationList command :-) Really smooth and elegant solution... I still don't know all the commands that GeoGebra offers ... but now when I think about it I could have search through all commands with the key term "iteration" based on what I need ...

Anyway, thank you very much!

photo
© 2017 International GeoGebra Institute