[Home]

[First Examples]

[Resp. Analysis]

[Exercises]

[JavaScript]

GeoScript-Syntax Short Reference

1 Standard functions and operations

In GeoScript terms you can use all common operations (+, - , * , /, ^), some standard functions (sqrt, sin, cos, tan, atan, asin, acos, sec, csc, cot, min, max, abs, log, exp) as well as arbitrary nesting of parenthesis. The trigonomic functions are used the rad format. Logic function are: AND, OR, XOR. The negation is realized as a function not().

2 GeoScript functions

In GeoScript you can also use functions, which delivers values like the distance of two points, the size of an angle, and so on. All these function are realized in the Java class Measure. The following list shows some examples:

 

  • "angle(P1, P2, P3)"
    Returns the value of the angle of the three points <P1P2P3.
  • "isIncident(P1, Obj1)"
    The return value is 1 (is 0), if point P1 is (not) incident with Obj1, and Obj1 could be a point, line or circle.
  • "isIncluded(P1, Obj1)"
    The return value is 1 (is 0), if point P1 is (not) included in Obj1, and Obj1 could be a circle or a polygon.
  • "isIncident(P1, Obj1)"
    The return value is 1 (is 0), if point P1 is (not) incident with Obj1. Obj1 could be a point, line or circle.
  • "distance(P1, P2)"
    Returns the Euclidean distance of the points P1 and P2.
  • "xCoordinate(P1)"
    Returns the x-Coordinate of the point P1.
  • "yCoordinate(P1)"
    Returns the y-Coordinate of the point P1.
  • "xVector(P1, P2)"
    Returns the x-Component of the vector given through the points P1 and P2.
  • "yVector(P1, P2)"
    Returns the y-Component of the vector given through the points P1 and P2.

In you would like to use the actual value of an existing Measure object (MObj) in a term, you can use the "calculate(MObj)" command.

Example: If in a GeoScript figure exists a Measure object M1, then the term “calculate(M1) * 0.5” delivers half of the value of M1.

3 Control elements

Sliding control elements

are implemented by the Measure subclass Controller. With them numeric values from a given interval can be adjusted, which can serve as parameters for the definition of geometrical objects. As object data are to be indicated: an initial value a, the incrementation step s, an interval [x0x1], the width b of the sliding control in pixels as well as a prefix and a postfix string.

Object label

Class name

Subclass name

Object data

<name [string]>

measure

controller

<a [double]>,

<s [double]>,

<x0 [double]>,

<x1 [double]>,

<b [integer]>,

<prefix [string]>,

<postfix [string]>

Button elements

Are realized by the subclass Button. By clicking a button element with the computer mouse an event is released, which is specified through variable e in the object data. The following events are possible:

e = reset: The figure is reset into the initial condition.

e = help: A help text is displayed.

e = evaluate: The response analysis is called.

e = cleartrace: All tracks of point objects in the drawing plane are deleted.

Object label

Class name

Subclass name

Object data

<name [string]>

measure

button

<label [string]>,

<e [string]>

Checkbox elements

are implemented by the subclass Checkbox. A checkbox can take only the values 1 and 0. As object data an initial value i and a label are to be indicated.

Object label

Class name

Subclass name

Object data

<name [string]>

measure

checkbox

<label [string]>,

<i [0 or 1]>

4 Geometric objects

Points with randomised coordinates

are implemented in the class Random. Two intervals [xmin, xmax] and [yminymax] are to be indicated as object data. Furthermore you had to determine if the coordinates should be in the integer or real format.

Object label

Class name

Subclass name

Object data

<name [string]>

point

random

<xmin [double]>,

<xmax [double]>,

<Ymin [double]>,

<Ymax [double]>,

<[”integer” or “real”]>

Function dependent points

are produced by the class FunctionDepend. Two coordinate functions f(x) and f(y) are to be indicated as object data, which are defined by two objects of the class MeasureCalculate.

Object label

Class name

Subclass name

Object data

<name [string]>

point

functiondepend

<f(x) [measure]>,

<f(y) [measure]>

Parametric curves

can be implemented by the subclass Curve. They will be defined through two functions fx(t), fy(t), which are implemented by objects of the class MeasureCalculate. The curve parameter t goes through the interval [t0, t1]. Furthermore a number n of points is to be indicated, by whom the curve is approximated.

Object label

Class name

Subclass name

Object data

<name [string]>

line

curve

<fx(t) [measure]>,

<fy(t) [measure]>,

<t0 [double]>,

<t1 [double]>,

<n [integer]>

5 Special functions

Showing and hiding objects

This could be realized with the help of a list hidden[1..n]. Each list entry consists of the specification Measure term t and a number of object labels Obj1, Obj2, …. The indicated objects are hidden, as soon as t takes the value 1. Example:

We say there is given before a checkbox element cb. Then the term “calculate(cb)” delivers the actual state of the checkbox. So the objects Obj1, Obj2 are hidden, if the checkbox is checked.

hidden[1] = "if (calculate(cb)) hide (Obj1, Obj2)"

 

6 Using the interface to JavaScript

Calling a JavaScript-function from GeoScript

To invoke a JavaScript function “Param 1”, one had to use the following GeoScript syntax. The parameters “Param 2”, “Param 3”, etc. are given as string objects to the JavaScript function. They are also used as parent objects of the JavaScript functions. This means, that the function is every time called, if the parent objects are updated.

Object label

Class name

Subclass name

Object data

<name [string]>

measure

JSfunction

<”Param 1” [string]>,

<”Param 2” [string]>,

<”Param 3” [string]>,

...

Defining a JavaScript function in an HTML document

The name of the JavaScript function can be chosen arbitrary. But the return value of the function can’t be given back directly (this would not be supported by Internet Explorer), so there must be defined a global variable result, which is used for the return value. After calling a JavaScript function, Geometria reads the return value from this variable.

Interaction with HTML elements

If an HTML element (checkbox, button, etc.) changes the value of the JavaScript function, then Geometria must be invoked to call the JavaScript function again. This will be reached through document.Geometria.repaint().

Getting values from Geometria to JavaScript

To get actual values from the Applet (e. g. coordinates of a special point) one can use the command document.Geometria.getValue("name","property"). The "name" should be the label of an object, the "property" refers to an object property. For example document.Geometria.getValue("A","x") delivers the x-coordinate of the point A.

If one uses the getValue command without defining a property, like document.Geometria.getValue("name"), then "name" should be the label of an measure object.

Allowing JavaScript to call Java functions

To allow JavaScript calling some public methods of an applet, the applet definition must be extend with the MAYSCRIPT command. Example:

<applet code="Geometria" width="640" height="480" ... name="Geometria" MAYSCRIPT>