Recent Changes - Search:

Information

Installation

Documentation

ElementsTrail2D

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.

(:applet clickimg="ODEplotter.jpg" clickalt="" clickcaption="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." code="ODEplotter_pkg.ODEplotterApplet.class" codebase="http://www.um.es/fem/EjsDL/Examples/Elements/Drawables2D" archive="ejs_ODEplotter.jar" width="639" height="357" draggable="true" :)

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.

(:applet clickimg="Curve2D.gif" clickalt="" clickcaption="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." code="TrailExample_pkg.TrailExampleApplet.class" codebase="http://www.um.es/fem/EjsDL/Examples/Elements/Drawables2D" archive="ejs_TrailExample.jar" width="486" height="465" draggable="true" :)

More examples

Properties

Property values in the 2D Trail inspector

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.
NameDescriptionValues acceptedDefault
Input XThe 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 YThe 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.
NameDescriptionValues acceptedDefault
Pos XThe X coordinate for the element.A constant or variable of type double or int.0
Pos YThe 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 XThe size of the element in the X direction.A constant or variable of type double or int.1
Size YThe 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.
TransformThe transformation to apply to this element.Use the editor provided or read more About 2D transformations. 
Visibility and Interaction
NameDescriptionValues acceptedDefault
Menu EntryThe 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.
VisibleThe visibility of the element.A boolean variable or one of the constants true or false.true
MeasuredWhether the element must be considered by its parent panel when autoscaling.A boolean variable or one of the constants true or false.true
DraggableWhether 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 GroupIf 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
SensitivityThe size of the hot spot (the selection area around the element's position), in pixels.A constant or variable of type int.5
On PressThe action to invoke when the element is pressed.The Java code to invoke for the action. 
On DragThe action to invoke when the element is dragged.The Java code to invoke for the action. 
On ReleaseThe action to invoke when the element is released.The Java code to invoke for the action. 
On EnterThe action to invoke when the mouse enters the element.The Java code to invoke for the action. 
On ExitThe action to invoke when the mouse leaves the element.The Java code to invoke for the action. 
Graphical Aspect
NameDescriptionValues acceptedDefault
Max PointsThe 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 InputWhether 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
SkipThe 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
ActiveWhether the element actually accepts input data.A boolean variable or one of the constants true or false.true
No repeatWhether to ignore equal successive points.A boolean variable or one of the constants true or false.false
ConnectedWhether to connect each point to the next one.A boolean variable or one of the constants true or false.true
Line ColorThe color used for the lines of the element.Use the editor provided or read about colors.BLACK
Line WidthThe 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
NameDescriptionValues acceptedDefault
X Data ColThe label for the X column when displayed in a data tool.A String constant or variable. 
Y Data ColThe 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.

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