Get object's definition

Clueid shared this question 4 months ago
Answered

Hello,

Is there a command or a way to get some object's definition? It's something similar to Name(),

Comments (32)

photo
2

https://wiki.geogebra.org/e...

(with second parameter = false)

photo
1

How can I make it input it in Execute() command?

Execute({FormulaText(g, false)})


gives me: undefined variable.

photo
2

Try: Execute({"g=("+FormulaText(f,false,false)+")"})

Note: Bolt are constants, italic are variables

.

But this make 2 time no sense

  • Execute({"g=f"}) is more easy and clear
  • more then make a (dependend) copy is not possible (?)

So i think: the question is not "how get objects definitions", the question is what you want achieved and after this the question how you can do this.

photo
1

My goal is to get all possible intersections of a regular n-gon.


Sure, I can do it by nested zip() command:

Flatten(Zip(Zip(Intersect(P, Q), P, {SegmentList}), Q{SegmentList})

But the problem is that the output is an aggregated list of points. This is a problem for me because 1. I want to interact with the points by drawing segments circles etc... 2. Even after separating the points using a sequence, the points do not inherit the original definitions, but rather elements from SegmentList().

photo
1

Also, suppose I have a free point P on a circle or a line, etc.. and I want to get another free point Q having the same definition of P (i. e: Point(c)) but without having the same exact value

photo
1

Is there a way to fix this code :( ?


Execute({"Var="+FormulaText(%1, false, false)}, C)

photo
2

Bitte sende Dein Applet als GGB-File.

photo
1

This is the first application of my question...

photo
photo
2

attached a sample without FormulaText.

l5 is the generated script-list to create the named point.

(I think you mean not free points instead you mean full depended, named points. )

---------------------------

For me is absolutely not clear why you need the named points. If I wanted to construct something with the points, I would create more objects in a list with an iteration (sequence or zip) based on l4.

For this (depending what you want do) you need maybe the points in separate lists (For example same distance from center and/or same difference angle to the next corner and/or sorted by the polar-vector etc.)

This splitting in differences lists (starting from l4) is also possible with iterations in the algebra view. If you want use scripts to do this you become big problems (performance, consistence, bugs in context of change corner-count etc.).

------------------------

Maybe the named points are useful to try something temporarily (manually with the tools). After click the button: all Points are deleted (and new created) so also the temorarily objects are deleted.

-----------------

I change the zip to sequence (a matter of preferences)

I change the polygon definition (more control for the followings)

I check the number of objects. I think it's correct (was not trivial) but no garantie

-----------------------------------

Maybe you don't know all the used commands. If something not clear: ask.

photo
1

Thank you for your reply.


"you mean full depended, named points."


Yes, for this certain case, I need dependent points.


"not clear why you need the named points"


It may not be clear in the example of the regular polygons. But I to get object's definition for other instances.


I use GeoGebra to illustrate complicated geometry problems. Sometimes it's very useful for me to "bulk intersect" two lists of objects such that the points of intersection have clear definitions for me (not element(l1, 3), which is not clear).


To put it simply. I just want to automate these commands (I want the same output, not element(l3, 5)):


Intersect(line1, circle1),


Intersect(line1, circle2),Intersect(line1, circle 3),

Intersect(line2, circle1),

Intersect(line2, circle2),

Intersect(line2, circle3)

photo
photo
2

I think it's not possible because an Element of a list is not an object but it's a reference to a process (with commands or pointers)

Only named obects contain GGB-Commands in FormulaText.

Elements in lists contain never GGB-Commands in the FormulaText.

--------------------

See the 2 experiments in the attachment

photo
1

That's why all I need is to fix this code: if there's a way to use "FormulaText()" inside Execute() I'll be done.


Execute({"Var="+FormulaText(%1, false, false)}, C)

photo
2

Explain more with example:

What is the definition of the object contain this script

What is the value of the object contain this script

What is the definition and the value of C

What result you expect where and how (Definition and Value)

------------------

if possible create a ggb-file for the example (also then, when the script not works)

photo
1

All I need is to copy the definition of a point C into a new point.


Example: c = Circle((0,0), 1), C = Point(c). I want: a point P with the same definition as C but without coinciding with it.


Sure I can simply put P = Point(c), but that's not a solution when it comes to big and more complicated diagrams.


Please check the attachments:

photo
2

maybe this?

photo
2

variant with (multi) copy by each click.

I think it does what you described in the sample. But the sense still eludes me.

photo
1

That's perfect. You really deserve a medal for helping me this much. I really appreciate your work :D


I'll give you the script that I worked on, and hopefully it will make sense for you ;)


A script for snapping a point to a point:

Problem: given a point on the plane S and a free point P, we wish to snap P to S whenever P becomes close to S.


Solution: we define another hidden point H having the same definition as P (since P can be a free point on a circle or a line). Now, we apply the following code:


P = DynamicCoordinates(H,
    If(Distance(H, S) < 0.1, x(S), x(H)),
    If(Distance(H, S) < 0.1, y(S), y(H))
    )

Now, we can make it better, by making the points arbitrary and I can just copy-paste the script and enter any points I want:

Execute({"
	%2 = DynamicCoordinates(%3,
	If(Distance(%3, %1) < 0.1, x(%1), x(%3)),
        If(Distance(%3, %1) < 0.1, y(%1), y(%3))
    )
"}, S, P, H)
Notice the code above, the hidden point H must be constructed as the same definition as P. Thus, we can make it better if H is defined by the code itself. With something like this:

Execute({"H = "+FormulaText(%2, false, false),
	"%2 = DynamicCoordinates(%3,
	If(Distance(%3, %1) < 0.1, x(%1), x(%3)),
        If(Distance(%3, %1) < 0.1, y(%1), y(%3))
    )
"}, S, P)

The bad news, it does not work :(


I hope it makes sense now.

photo
2

I am beginning to understand (probably)

The not working applet as ggb-file would be very helpful for the exact understanding.

----------------------------------

I suspect that similar to the different ggb-grid images (Cartesian, Isomtric, Polar ) you want a freely constructed grid (dots, paths) where free points can snaps to.

If yes: I have something ready-made in my fundus, which can be extended (but it is not based on FormulaText)

photo
1

Rami, that's awesome! I have a question for this application, so I made a new post in "Get current zooming factor".

photo
1

That's the ggb file that you asked for:

photo
1

The files that you've sent (definition copy and definition copy_2) are exactly what I want. But is there a way to do it without buttons?


If there is such way, then we can fix this code


Execute({"H = "+FormulaText(%2, false, false),
	"%2 = DynamicCoordinates(%3,
	If(Distance(%3, %1) < 0.1, x(%1), x(%3)),
        If(Distance(%3, %1) < 0.1, y(%1), y(%3))
    )
"}, S, P)

photo
2

Sorry, I don't understand what you want.

The (fix) script autside a context is not clear and maybe wrong (for example all %n )

When you want a button then the questions are:

  • how the script in the button know what is the point there is to copy
  • and where is the place for the new point
  • and the place must be fix or can be move (with mouse) on the same path as the original
  • and was must be happen when the original point is not movable (for example an Iîntersect)
  • and one point can have only one copy or multiple
  • and what is the name of the new point.

Maybe you can express your wish in words. It would also be helpful to know why you prefer a button.

photo
1

Hello,

I said "is there a way to do it without buttons".

I just want it pure script.

The two examples you sent are perfect for me. This is what I want. And here's my question:

"In your example, is there a way to do it without pressing on point C?"

I just want it (copy and paste through the command line then enter my points and done.)

Is it possible to do this?

photo
2

I think it's not possible.

The script need the name from C (the object for the FormulaText()). How when not with click? For this "How" I have no idea.

photo
1

Dear Rami,

You already have gave me the solution:

Execute({"P=("+FormulaText(C,false,false)+")"}) 

This simple code works. I want to add parameters to it and the problems is finished.

photo
1

By adding parameters, I mean:

Execute({"Var="+FormulaText(%1, false, false)}, C)

photo
2

Then say what parameter with what value and depending from what.

photo
1

The parameter is any object I want to copy (a point, a line, etc..)

It can have any value.

If the parameter is a dependent point then the whole command would be a dependent point.


I encourage you to play with this code, it just works the exact way I want:

Execute({"P=("+FormulaText(C,false,false)+")"}) 

Just create any point C, (whether on an intersection, path, circle, whatever, the code still works) and apply the code. The result is what I want.

photo
2

What you can do:

  • copy the script above in the input-Bar
  • Change the Name "P" or use only: Execute({"("+FormulaText(C,false,false)+")"})
  • Change the Label C (to the Label of an exist Object)
  • Press Enter

photo
1

Note that the parameter is the targeted point not the resulting point. I can change the name of the resulting point easily. My problem is with choosing which point to copy. That's why I want to make it a parameter.

photo
2

You are in a never ending loop.

Maybe someone else can solve your Problem. I can't.

photo
1

Sorry for that, and thank you for your patience.

photo
© 2020 International GeoGebra Institute