Interaction with Geometry
CindyScript can interact in different ways with a geometric drawing that was created with Cinderella. We already saw that it can read the numerical data and appearance of geometric elements. However it can also change the position of the free elements of a construction. CindyScript may even inquire and change the construction sequence by creating and deleting new geometric elements.
The calculations within CindyScript can be used to control the positions of free elements in a Cinderella construction. One way of doing this is to explicitly set the position information of a free element. For instance, if
is a free point, the line
sets this point to the coordinates
. Another way of moving an element is with the
Moving a Free Element:
Description: In this operator,
<geo> is a free geometric object and
<pos> (usually a vector) describes a position to which this object should be moved. Calling this operator simulates a move for this geometric object.
is a free point, then
can be a list
of two numbers or a list
of three numbers. The first case is interpreted as Euclidean coordinates, while the second case is interpreted as homogeneous coordinates and sets the point to
is a free line, then
has to be a list of three numbers
, and the line is set to the line described by the equation
a∗x + b∗y + c = 0
Examples: The following code lines summarize possible ways to move geometric elements (we also include the possibilities of moving elements by accessing their data fields):
//A is a free point
moveto(A,[1,4]); //moves A to Euclidean coordinates [1,4]
A.xy=[1,4]; //moves A to Euclidean coordinates [1,4]
A.x=5; //sets the x coordinate of A to 5, lets the y coordinate unchanged
A.y=3; //sets the y coordinate of A to 3, lets the x coordinate unchanged
moveto(A,[2,3,2]); //moves A to homogeneous coordinates [2,3,2]
A.homog=[2,3,2]; //moves A to homogeneous coordinates [2,3,2]
//a is a free line
moveto(a,[2,3,4]); //moves a to homogeneous coordinates [2,3,4]
a.homog=[2,3,4]; //moves a to homogeneous coordinates [2,3,4]
//b is a line through a point
b.slope=1; //sets the slope of the line to 1
//C is a circle with free radius
C.radius=1; //sets the radius of the circle to 1
Handles to Objects
Who has moved:
Description: This operator gives a handle to the element that is currently moved by the mouse.
Elements close to the mouse:
Description: This operator gives a list with handles to all the elements that are close to the current mouse position.
Example: The following script is a little mean. Putting it into the mouse move slot will make exactly those elements disappear that are close to the mouse. They reappear if the mouse moves away again.
Incidences of an object:
Description: This operator returns a list all the elements that are generically incident to a geometric element
Getting an element by name:
Description: This operator returns the geometric object identified by the name given in
element operator is necessary for situations where the element name is not a valid variable identifier or already used by a user-defined or built-in name. For example, if you try to access the color of a line having the name
i, you cannot write
i is reserved for the complex unit. Instead, you use:
Creating and Removing Elements
Creating a free point:
Description: This operator creates a new point with label
<string>. The point will beset to position
<pos>. If an element with this name is already exists then no new element is created. However, if there already exists a free point with this name, then this point is moved to the specified position.
Creating a geometric element:
Description: With this operator it is possible to generate arbitrary geometric elements that are functional in a geometric construction. Due to the fact that algorithms may create multiple outputs several subtleties arise. This function is meant for expert use only.
The first list contains a list
of element names for the generated output objects of the algorithm.
is the internal name of the geometric algorithm. The second list
is a list of the parameters that are needed for the definition. The following table shows a few possible creation statements.
This sequence of statements creates the fully functional construction shown below.
Observe that in the sixth statement when two circles are intersected there must be a list of two output elements specified.
You can find the valid parameters for elements by constructing them manually and using the
functions described below.
Removing a geometric element:
Description: Removes a geometric element together with all its dependent elements from a construction.
Input elements of an element:
Description: This operator returns a list all the elements that are needed to define the object
<geo>. These may be other geometric, elements, numbers or vectors.
Algorithm of an element:
Description: This operator returns a string that resembles the algorithm of the definition the object
Example: The following piece of code generates all information contained in a construction sequence.
Applied to the construction of a perpendicular bisector in the picture below it generates the following output:
Accessing Element Properties
Element properties like color, size, etc. are conveniently accessible via operators like
etc. However, elements have by far more properties. All of them can be generically accessed by the following operators.
List all inspectable properties:
Description: Returns a list of names of all private properties of a geometric element.
Example: The operator
inspect(A) applied to a the free point A returns the following list of property names.
Accessing an inspectable property:
Description: Accesses an arbitrary inspectable property.
Example: One can access the color of a point A by
Setting an inspectable property:
Description: Setting the value of inspectable property.
Example: One can set the color of a point A to white by
Forcing a repaint operation:
Description: This operator causes an immediate repaint of the drawing surface. This operator is meant to be used whenever a script has updated a construction and wants to display the changes. It is not allowd to use this operator in the
draw or in the
Forcing a delayed repaint operation:
repaint but with a time delay of as many milliseconds as given by he parameter
Points on a locus:
Description: This operator returns a list of points in xy-coordinates that are all on a locus given by the name
<locus> of a geometric element.