Is it possible to define reusable user functions or scripts?

ariznaf shared this question 6 years ago

I know there is a Function command, but it seems it is oriented to define univariable curves or two variable surfaces.

What I am looking for is a way of defining a reusable piece of code that accepts several Geogebra objects as parameters and returns another object as result.

For example, I need to créate a unit vector from the dip and dip direction of a plane that represents its normal vector.

Now I have to key the equations for each plane I have.

I would like something like (using pseudocode):

[Vector] normalVectorFromDip(Angle dip, Angle dipDir)


local n= Vector[]

....code goes here.....

return n


Is there a way to define user code functions in Geogebra?

Comments (7)


Hi ariznaf

it had been my dream to be able to do that with Geogebra

then I would have imagined a website or all functions created by users have been available to other users. :anguished:


What I am looking for is a way of defining a reusable piece of code that accepts several Geogebra objects as parameters and returns another object as result.

See here:


That sounds promising. I have to look at custom tools in depth.

They seem the way to recreate complex constructions.

But they don't seem exactly what I meant.

For example:

I have to use some calculus to Project a point usin steregraphic projection.

A 3D (x,y,z) point is transformed in a 2D point using this transformations:

X= x/(1-z)

Y= y/(1-z)

I have to repeat the formulas every time I have to Project a point, wiche is tedious.

Having a function like:

<Point> stereoProject(<Point> P)


local <Point> p;

x(p)= x(P)/(1-z(p));

y(p)= y(P)/(1-z(p));

return p;


would be of greate help.

Another use is to construct a unity vector given its trend and plunge:

<Vector> vectorByTrendPlunge(<Angle> trend,<Angle> plunge)


local <Vector> v;

x(v)= cos(plunge) sin(trend);

y(v)= cos(plunge) cos(trend);

z(v)= -sin(plunge);

return v;


It seems Geogebra uses JavaScript extensively.

Integrating a JavaScript interpreter in Geogebra and being able to use it to define custom commands would be great.

thanks for your help and your pointing to custom tools.


Custom tools may be of help for doing the projection.

But it seems that they don't work with 3D objects.

I have constructed one in 2D view and it worked, but in 3D view it is not available.

I tried to créate one in 3D view, using a 3D point A and the projected point B in the 3D view.

But the points A and B are not available as input and output objects.


Please post your .ggb files


Here you are.

It is a very simple one:

just a point A and the projected point B calculated from it.

I try to créate the custom tool using point B as output and Point A as input.

But there is no object to select in the dialog box.

If I créate the points in 2D view, I can select the input and output points.

But in 2D view you have just 2D points and I need my construction in 3D.


It seems that the last update (5.029) has solved this problem too.

Now I can use de custom tool with the point constructed in the 3D view.

But the icon of the custom tool in the toolbar only appears when you select the2D view, in the 3D view it disappers (I don't know if this is the normal behaviour, as a tool may be design only to be use under 3D or 2D).

But the custom tool was built with the 3D view active.

Great work!!

© 2021 International GeoGebra Institute