Recent Changes - Search:

Information

Installation

Documentation

 

 « Polygon | Sitemap | Group » 

Trail

A trail is a two-dimensional drawable that displays a collection of points in the plane. The points are added to the trail either through the Input X and Input Y properties, or using the element’s addPoint or moveToPoint methods. The points are displayed using lines which connect the points, each with the previous one, thus forming a polygonal line (which looks like a trail). The trail can be disconnected at some points if the Connected property is set temporarily to false, of if the moveToPoint method is used. The number of points in a trail can be limited through the Max Points property. Adding points past the limit causes the trail to remove the first points in it.

 

Click on the image to start the applet.

A simple Trail2D example: the Input properties of two 2D trails are used to plot the solution curves of a second order differential equation. Download this example.

 

Trails can be broken into several segments using the newSegment method. Each segment behaves like a sub-trail, but segments can have different drawing styles (line width and color). Also, the user can delete the points in the last segment without affecting the previous segments.

 

Click on the image to start the applet.

A more sophisticated Trail2D example: the addPoint() and moveToPoint() methods of a 2D trail are used to create separated plots for parametric curves of the plane. Download this example.

 

 

More examples

 

 

Properties

Property values in the 2D Trail inspector

 

Trail2D  
Input
Specifying input properties is the standard way of adding points to the trail. EJS will add a new point to the trail using the values indicated by these properties if any of them is specified. If both properties are left empty, then then no point is added via input properties, and you will need to add points to the trail by using the addPoint() method.  
Name Description Values accepted Default
Input X The X coordinate of the point to add. A constant or variable of type double or int. A double[] array can also be specified, in which case EJS will add one trail point for each of the entries of the array. By default the input value is taken to be zero (if the other input property is specified).
Input Y The Y coordinate of the point to add. Same as Input X.
Position and Size
Position and size properties can affect the final position of the point added to the trail by translating, resizing and rotating the whole trail. Default values do not modify the trail.  
Name Description Values accepted Default
Pos X The X coordinate for the element. A constant or variable of type double or int. 0
Pos Y The Y coordinate for the element. A constant or variable of type double or int. 0
Position [] The double[] array with the coordinates of the shape. A double[2] array. Not specified by default.
Size X The size of the element in the X direction. A constant or variable of type double or int. 1
Size Y The size of the element in the Y direction. A constant or variable of type double or int. 1
Size [] The double[] array with the size of the shape in each direction. A double[2] array. Not specified by default.
Transform The transformation to apply to this element. Use the editor provided or read more About 2D transformations.
Visibility and Interaction
Name Description Values accepted Default
Menu Entry The name that will appear in the simulation menu for options related to this element. A String. By default, the name of the element (in the Tree of Elements of the View) is used.
Visible The visibility of the element. A boolean variable or one of the constants true or false. true
Measured Whether the element must be considered by its parent panel when autoscaling. A boolean variable or one of the constants true or false. true
Draggable Whether the element can be dragged (by clicking in its (Pos X, Pos Y) point). A boolean variable or one of the constants true or false. false
Drag Group If true, and if the element forms part of a group, dragging the element will move the whole group. A boolean variable or one of the constants true or false. false
Sensitivity The size of the hot spot (the selection area around the element’s position), in pixels. A constant or variable of type int. 5
On Press The action to invoke when the element is pressed. The Java code to invoke for the action.
On Drag The action to invoke when the element is dragged. The Java code to invoke for the action.
On Release The action to invoke when the element is released. The Java code to invoke for the action.
On Enter The action to invoke when the mouse enters the element. The Java code to invoke for the action.
On Exit The action to invoke when the mouse leaves the element. The Java code to invoke for the action.
Graphical Aspect
Name Description Values accepted Default
Max Points The maximum number of points of the element. Adding more points than the maximum forces the trail to delete the first points in it. This property is used, sometimes, to reduce the graphic overload when a very large (how large depends on your computer power and memory) number of points is added to a trail. A constant or variable of type int. The default value is 0, fixing no limit.
Clear at Input Whether the element should clear all its existing points before adding the current input. This is typically useful when your input consists of a pair of double[2] arrays which make a whole trail, and all the points in this trail change in time. A boolean variable or one of the constants true or false. false
Skip The number of input points to skip before plotting one. This value is useful when your program computes many points close to each other and you want to reduce the number of points to plot (so that to reduce the graphic overload). A constant or variable of type int. 0, which means all input points are plotted
Active Whether the element actually accepts input data. A boolean variable or one of the constants true or false. true
No repeat Whether to ignore equal successive points. A boolean variable or one of the constants true or false. false
Connected Whether to connect each point to the next one. A boolean variable or one of the constants true or false. true
Line Color The color used for the lines of the element. Use the editor provided or read about colors. BLACK
Line Width The thickness for the lines of the element. A constant or variable of type double or int indicates the thickness. Note that non-integer values, such as 1.5, are accepted. 1
Table Labels
Name Description Values accepted Default
X Data Col The label for the X column when displayed in a data tool. A String constant or variable.
Y Data Col The label for the Y column when displayed in a data tool. A String constant or variable.

 

Public methods of the 2D Trail element that can be invoked in a code page

 

Signature and description

void addPoint(double x, double y). Adds a new point (x,y) to the trail. The point is connected to the previous point, if the Connected property is set to true. The following sample code displays the graph of the sine function in the interval [0,2 Pi] using a Trail2D element called trail:
double tMin = 0, tMax = 2*Math.PI;
int nPoints = 100;
for (int i=0; i<nPoints; i++) {
  double t = tMin + i*(tMax-tMin)/(nPoints-1);
  _view.trail.addPoint(t,Math.sin(t));
}

void addPoint(double[] point). Equivalent to addPoint(point[0],point[1]).

void moveToPoint(double x, double y). Adds a new point (x,y) to the trail which is not connected to the previous one.

void moveToPoint(double[] point). Equivalent to moveToPoint(point[0],point[1]).

void addPoints(double[][] input). Adds an array of new double[] points to the trail. input must be a double[nPoints][2] array with the coordinates of the points.

void addPoints(double[] xInput, double[] yInput). Adds an array of points to the trail. xInput and yInput must be double[] arrays with the X and Y coordinates of the points to add, respectively.

void clear(). Clears all points from all segments of the trail.

void initialize(). Clears all points from the last segment of the trail, respecting previous segments.

void newSegment(). Creates a new segment of the trail.

 



 « Polygon | Sitemap | Group » 

Edit - History - Print - Recent Changes - Search
Page last modified on December 07, 2010, at 01:17 PM