Curve

Curve is one of the of primitive presentation shapes that you can use to draw presentations for your models.

Curve is a freeform shape that is drawn in the same manner as a polyline - as a set of vertices that are sequentially connected. The difference is that the curve vertices are connected not to the straight lines, but to the curve segments, that make up a periodic spline.The picture below shows you a polyline and a curve, both drawn for the same set of vertices:

 To draw a curve
  1. Double-click the  Curve element in the  Presentation palette.
  2. The icon of the element should turn into . It means that the drawing mode is activated and now you can draw a curve in the graphical editor point by point.
  3. Click in the graphical editor at the position of the first point of the curve.
  4. Subsequently click at other points where you want to place other salient points.
  5. Double-click to place the end point and finish drawing.
  6. To create a closed curve you should not create its first and last points at the same position. Instead, you should check the Closed checkbox in the its properties. The last edge is then drawn automatically.
Each vertex of the curve can be controlled during the model execution. You can specify dynamic expression, defining the number of vertices. The coordinates of the curve’s vertices can also be defined using dynamic expressions.

Properties

General

Name – The name of the shape. It is used to identify and access the shape from code.

Ignore – If selected, the shape is excluded from the model.

Visible on upper level – If selected, the shape is also visible on the upper level where this agent lives.

Icon – If selected, the shape is considered as a part of the agent's icon. Please note that icon shapes are not shown in 3D animation.

Lock – If selected, the shape is locked. Locked shapes do not react to mouse clicks - it is impossible to select them in the graphical editor until you unlock them. It is frequently needed when you use a shape as a background image for your animation and you want to prevent editing this shape while drawing other shapes over it.

Visible – Here you specify whether the shape is visible on the animation at the model runtime, or not. Choose yes or no using the control. If you expect visibility to change dynamically or to depend on some conditions, you may specify the expression defining the shape's visibility here. This expression will be dynamically reevaluated at the model runtime. It should return boolean value. The shape is visible when the specified expression evaluates to true, and not visible otherwise.

Closed – If selected, the curve is closed, i.e. its begin and end point are connected with extra segment.

Appearance

Line color – Curve color. Click inside the control and choose the required color using the Colors dialog box. Choose No Line, if you do not want the curve to be drawn.
You can specify the expression that will be reevaluated dynamically. It should return instance of Color Java class.

Fill color – Curve's fill color. The curve is painted in the following way: the line connecting curve's start and end points is drawn (if the curve is not closed already) and the area inside the resulting shape is painted over. 
Click inside the control and choose the required color using the Colors dialog box. Choose No Fill, if you do not want area inside the curve to be filled.
Otherwise, specify here the expression defining the shape's fill color. The expression should return an instance of Java class Color. If it returns null, the shape is not filled. 

Line width – The line width. Choose width from the drop-down list, or enter the value in pixels in the field to the right. 

Line style – [Enabled only if the 2D only option is selected in the Show in advanced property] The line style. Choose from the drop-down list, whether you want solid, dashed, or dotted line to be drawn. 

Position and size

X – X-coordinate of the curve (its start point).

Y – Y-coordinate of the curve (its start point).

Rotation, rad – The shape's rotation angle in XY plane. 

Scale X – Here you can specify the expression returning the X-direction scale factor for the shape.*

Scale Y – Here you can specify the expression returning the Y-direction scale factor for the shape.*

* You can dynamically scale the shape at the model runtime by specifying expressions in the Scale X and ScaleY parameters.

Points

Number of points – Here you can specify the expression that will return the number of points of the curve.

dX[indexPt] – Here you can specify the expression for the X-offset of the curve's point with the index indexPt regarding the start point of the curve. Use the predefined symbol indexPt to refer to the current point index. The index value is zero based, i.e., the first point has index of 0.

dY[indexPt] – Here you can specify the expression for the Y-offset of the curve's point with the index indexPt regarding the start point of the curve. Use the predefined symbol indexPt to refer to the current point index. The index value is zero based, i.e., the first point has index of 0.

Advanced

Replication – The replication factor of the shape. Here you specify how many copies of the shape will be created (the integer number). If you leave this field empty, only one shape will be created.

On click – Code that will be called each time a user clicks on the shape at the model runtime.

Control points are set - here you can choose whether the control points of the curve are set automatically, or manually. Manually means that the "editing curve with the help of guiding lines" mode is switched on. It provides widely spread and convenient way of curve editing, that enables users to draw curves of any complexity and form.

Show name – If selected, the shape's name will be displayed on a presentation diagram.

Changing curve appearance

You can change the appearance of the curve by editing its vertices.

 To switch to editing curve vertices mode
  1. Double click the curve, or
    Right-click (Mac OS: Ctrl+click) the curve and choose Edit Points from the popup menu.
  2. You will see curve vertices highlighted with small blue circles and straight lines connecting these vertices shown - it indicates that you have switched to editing curve vertices mode.
 To move a vertex of a curve
  1. Switch to editing curve vertices mode.
  2. Drag the curve's vertex.
 To add a new vertex to a curve
  1. Switch to editing curve vertices mode.
  2. Double-click on the straight line segment, connecting curve vertices, where you want to add a new vertex.
 To remove a vertex of a curve
  1. Switch to editing curve vertices mode.
  2. Double-click on the curve's vertex you want to remove.

Editing a curve using guiding lines

AnyLogic supports editing curves using guiding lines - widely spread and convenient way of curve editing, that enables users to draw curves of any complexity and form.

 To switch to "editing with the help of guiding lines" mode on

  1. Select the curve in the graphical editor or in the Projects view.
  2. Go to the Advanced section of the Properties view.
  3. Define the property Control points are set as Manually.

Let us explain how you can change a form of a curve using its guiding lines. We will illustrate results of operations by example of the curve drawn below:

 To start editing a curve using its guiding lines

  1. Switch "editing curve with the help of guiding lines" mode on.
  2. Switch to editing curve vertices mode
  3. You will see dotted lines tangent to curve vertices with little circles drawn on ends. These lines are guiding lines, and circles are markers.

Using these markers you can change length and orientation of the corresponding guiding line.

Changing orientation of a guiding line, you change form of curve segments adjacent to the corresponding curve vertex. 

 To change form of curve segments adjacent to a vertex

  1. Drag with the mouse any of two markers of a guiding line, tangent to the vertex. Move a marker clockwise or anticlockwise until segments will take the required form.
  2. The figure below illustrates how the rotation of the left vertex' guiding line affected the form of neighbouring curve segments:

Length of a guiding line defines a convexity of a curve segment in the corresponding vertex. 

 To change a convexity of a curve near a vertex

  1. Drag with the mouse any of two markers of a guiding line, tangent to the vertex. Move a marker away from the vertex or closer to it. Thereby you change the length of the guiding line. The more is the guiding line, the more bulged the curve segment is, and vice versa.
  2. The figure below illustrates how the stretching of the right vertex' guiding line affected the convexity of neighbouring curve segments:

All the described operations change the appearance of both curve segments, adjacent to the curve vertex from both sides.

However, sometimes you may need to change the appearance of only one particular curve segment. In this case you should work with only one marker, corresponding to this segment, as described below: 

 To change the position of only one particular marker

  1. Move the required marker using Ctrl+drag (Mac OS: Cmd+drag). 
Sometimes some guiding line may become "hidden" into the vertex as a result of your editing. For this case we provide one more special operation of "stretching" guiding line from a vertex.

 To show a hidden guiding line for a vertex

  1. Ctrl+drag (Mac OS: Cmd+drag) vertex aside. You will see a guiding line "appearing" from the curve vertex. 

Functions

Location

Function

Description

double getX()

double getY()

Returns the X (Y) coordinate of the shape (curve's start point).

void setX(double x)

void setY(double y)

Sets the X (Y) coordinate of the shape (curve's start point). This function not just changes the coordinate of the curve's start point, but moves the curve to the new location.

Parameters:  

x - the new value of X coordinate
y
- the new value of Y coordinate

void setPos(double x, double y)

Sets new coordinates for the shape (curve's start point). Z-coordinate is left unchanged. This function not just changes the coordinate of the curve's start point, but moves the curve to the new location.

Parameters:

x - the new value of x coordinate
y - the new value of y coordinate

Point coordinates, length

Function

Description

int getNPoints()

Returns the number of points of the curve. 

void setNPoints(int n)

Sets the number of points in the shape. Does nothing if the number of points equals the current one. If it is different, the maximum possible set of points keep their coordinates in the new shape.

Parameter:
n - the new number of points

double getPointDx(int i)

double getPointDy(int i)

Returns the X (Y) coordinate of a particular point of the shape relative to the start point.

Parameter:    
i
- the index of the point (starting from 0)

void setPoint(int i, double ptdx, double ptdy)

Sets the coordinates of a particular point of the shape relative to the start point. 

Parameters:
i - the index of the point (starting from 0)
ptdx - the new X coordinate of the point relative to the start point
ptdy - the new Y coordinate of the point relative to the start point

void setPointDx(int i, double ptdx)

void setPointDy(int i, double ptdy)

Sets the X (Y) coordinate of a particular point of the shape relative to the start point. 

Parameters:
i - the index of the point (starting from 0)
ptdx - the new X coordinate of the point relative to the start point
ptdy - the new Y coordinate of the point relative to the start point

boolean isClosed()

Returns true, if the curve is closed, and false otherwise.

void setClosed
(boolean closed)

Sets the curve closed or not.

Parameter:
closed - if true, the curve set to be closed, if false - not

Scaling

Function

Description

double getScaleX()

double getScaleY()

Returns the scale of the shape along X (Y) axis.

void setScaleX(double sx)

void setScaleY(double sy)

Sets the scale of the shape along X (Y) axis.

Parameters:
sx - the new value of scale along X axis *
sy - the new value of scale along Y axis *

* The value 1 means that the original size should be kept

void setScale(double sx, double sy)

Sets the scales of the shape along both axes.

Parameters:
sx - the new value of scale along X axis *
sy - the new value of scale along Y axis *

void setScale(double s)

Sets the same scale of the shape along both axes.

Parameter:
s - the new value of scale along both axis *

Rotation

Function

Description

double getRotation()

Returns the rotation of the shape in radians, clockwise.

void setRotation(double r)

Sets the rotation of the shape.

Parameter:
r - the new value of rotation in radians

Visibility

Function

Description

boolean isVisible()

Checks the visibility of the shape. If the shape is visible, returns true, otherwise returns false.

void setVisible(boolean v)

Sets the visibility of the shape.

Parameter:
v - visibility: if true - the shape is set to be visible, if false - not visible

Control points definition mode

Function

Description

boolean isManualControlPoints()

Returns true if this curve uses manually specified control points (which are specified in the dx and dy arrays) 

void setManualControlPoints(boolean manualControlPoints)

Sets control points mode: manual or automatic.
In the manual mode curve uses control points specified in the dx and dy arrays

Parameter:
manualControlPoints - true for manually specified control points, false for automatically calculated

Line appearance

Function

Description

Color getColor()

Returns the color of the line, or null if the line has no color or has texture (in this case getTexture() should be used instead) 

Texture getTexture()

Returns the line texture, if the line has texture.

void setColor(Color color)

Sets the line color.

Parameter:
color - the new line color, if null, the line is not drawn

void setColor
(Object color)

Sets the color (or Texture) of the line.

Parameter:
color - the new color, null = do not draw the line

double getLineWidth()

Returns the width of the line. 

void setLineWidth
(double width)

Sets the width of the line, 0 means thinnest possible.

Parameter:
width - the new width of the line

int getLineStyle()

Returns the style of the line, one of these three constants:

  • LINE_STYLE_SOLID - solid line

  • LINE_STYLE_DOTTED - dotted line

  • LINE_STYLE_DASHED - dashed line

void setLineStyle(int style)

Sets the style of the line, use one of these three constants:

  • LINE_STYLE_SOLID - solid line

  • LINE_STYLE_DOTTED - dotted line

  • LINE_STYLE_DASHED - dashed line

Parameter:
style - the new style of the line


Related topics

Moving Presentation Shapes

Resizing Presentation Shapes

Rotating Presentation Shapes

Changing Shape Color

Changing Shape's Line Appearance

Changing Shape's Position in Stacking Order

 Aligning Shapes

 API Reference: ShapeCurve Class