Class AnimationPath2D

All Implemented Interfaces:
Graph.Graphic, NamedObjectOps

public class AnimationPath2D extends AnimationObject2D
Class defining a path for animation objects. Some animation objects can follow a path. This class defines an animation object that can provide such a path and, if necessary, display it as part of an animation (displaying a path is useful for debugging).
  • Constructor Details

  • Method Details

    • setPath

      public void setPath(BasicSplinePath2D spath)
      Set the path.
      Parameters:
      spath - the path
    • initPath

      public void initPath()
      Initialize the path with a default winding rule.
    • getPath

      public BasicSplinePath2D getPath()
      Get the current path.
      Returns:
      the path
    • getMaxParameter

      public double getMaxParameter()
      Get the maximum value of the path parameter. This value is applicable for open paths, not closed paths. For closed paths, it represents the period at which the path is guaranteed to repeat. The returned value is numerically equal to the number of segments that make up the path.
      Returns:
      the maximum value of the parameter
      Throws:
      IllegalStateException - the path was not set
      See Also:
    • isClosed

      public boolean isClosed()
      Determine if the path is a closed path.
      Returns:
      true if it is closed; false if it is not closed
    • getX

      public double getX(double u) throws IllegalStateException, IllegalArgumentException
      Get the x coordinate for a given value of the path parameter.
      Parameters:
      u - the parameter
      Returns:
      the x coordinate of the point on the path for the specified parameter
      Throws:
      IllegalStateException - the path is not a simple path or was not set
      IllegalArgumentException - the parameter is out of bounds
      See Also:
    • getY

      public double getY(double u) throws IllegalStateException, IllegalArgumentException
      Get the y coordinate for a given value of the parameter.
      Parameters:
      u - the parameter
      Returns:
      the y coordinate of the point on the path for the specified parameter
      Throws:
      IllegalStateException - the path is not a simple path or was not set
      IllegalArgumentException - the parameter is out of bounds
      See Also:
    • getPoint

      public Point2D getPoint(double u) throws IllegalStateException, IllegalArgumentException
      Get the point on a path corresponding to a given value of the path parameter.
      Parameters:
      u - the parameter
      Returns:
      the point on the path corresponding to the specified parameter
      Throws:
      IllegalStateException - the path is not a simple path or was not set
      IllegalArgumentException - the parameter is out of bounds
      See Also:
    • dxDu

      public double dxDu(double u) throws IllegalStateException, IllegalArgumentException
      Get the derivative of the x coordinate with respect to the path parameter for a given value of the parameter.
      Parameters:
      u - the parameter
      Returns:
      the derivative
      Throws:
      IllegalStateException - the path is not a simple path or was not set
      IllegalArgumentException - the parameter is out of bounds
      See Also:
    • dyDu

      public double dyDu(double u) throws IllegalStateException, IllegalArgumentException
      Get the derivative of the y coordinate with respect to the path parameter.
      Parameters:
      u - the parameter
      Returns:
      the derivative
      Throws:
      IllegalStateException - the path is not a simple path or was not set
      IllegalArgumentException - the parameter is out of bounds
      See Also:
    • d2xDu2

      public double d2xDu2(double u) throws IllegalStateException, IllegalArgumentException
      Get the second derivative of the x coordinate with respect to the path parameter for a given value of the parameter.
      Parameters:
      u - the parameter
      Returns:
      the second derivative
      Throws:
      IllegalStateException - the path is not a simple path or the path was not set
      IllegalArgumentException - the parameter is out of bounds
      See Also:
    • d2yDu2

      public double d2yDu2(double u) throws IllegalStateException, IllegalArgumentException
      Get the second derivative of the y coordinate with respect to the path parameter.
      Parameters:
      u - the parameter
      Returns:
      the derivative
      Throws:
      IllegalStateException - the path is not a simple path or the path was not set
      IllegalArgumentException - the parameter is out of bounds
      See Also:
    • curvature

      public double curvature(double u) throws IllegalStateException, IllegalArgumentException
      Compute the curvature given path parameter. The curvature is given by the expression
          (x'y" - y'x")/(xp2 + y'2)3/2
       
      where the derivative are computed with respect to the path parameter, and is positive if the path turns counterclockwise as the parameter increases, is negative if the path turns clockwise, and is zero if the path follows a straight line. The radius of curvature is the multiplicative inverse of the absolute value of the curvature.
      Parameters:
      u - the path-segment parameter
      Returns:
      the curvature
      Throws:
      IllegalStateException - the path is not a simple path or the path was not set
      IllegalArgumentException - the parameter is out of bounds
      See Also:
    • dsDu

      public double dsDu(double u) throws IllegalStateException, IllegalArgumentException
      Get the derivative of the path length with respect to the path parameter for a given value of the parameter.
      Parameters:
      u - the parameter
      Returns:
      the derivative
      Throws:
      IllegalStateException - the path is not a simple path or the path was not set
      IllegalArgumentException - the parameter is out of bounds
      See Also:
    • getInversionLimit

      public double getInversionLimit()
      Get the inversion limit for the path. The inversion limit (a negative number indicates that the default should be used) is used by cubic splines used to map path distances to path parameters. The value supplied is used when a spline is created.

      Computing the inverse for a cubic spline in most cases requires solving a cubic equation, with valid solutions being in the range [0, 1]. The inversion limit allows solutions in the range [-inversionLimit, 1+inversionLimit] to be accepted, with values outside of the interval [0, 1] replaced by 0 or 1, whichever is closer. The use of an inversion limit allows for round-off errors.

      Returns:
      the inversion limit
      Throws:
      IllegalStateException - the path was not set
      See Also:
    • setInversionLimit

      public void setInversionLimit(double limit)
      Set the inversion limit. The inversion limit (a negative number indicates that the default should be used) is used by cubic splines used to map path distances to path parameters. The value supplied is used when a spline is created.

      Computing the inverse for a cubic spline in most cases requires solving a cubic equation, with valid solutions being in the range [0, 1]. The inversion limit allows solutions in the range [-inversionLimit, 1+inversionLimit] to be accepted, with values outside of the interval [0, 1] replaced by 0 or 1, whichever is closer. The use of an inversion limit allows for round-off errors.

      Parameters:
      limit - the inversion limit; or a negative number to indicate that the default will be used.
      Throws:
      IllegalStateException - the path was not set
      See Also:
    • getPathLength

      public double getPathLength() throws IllegalStateException, IllegalArgumentException
      Get the total length of the path.
      Returns:
      the path length
      Throws:
      IllegalStateException - the path is not a simple path or the path was not set
      IllegalArgumentException - the parameter is out of bounds
      See Also:
    • getPathLength

      public double getPathLength(double u1, double u2) throws IllegalStateException, IllegalArgumentException
      Get the length of a subpath. The returned value is the same if u1 and u2 are exchanged: lengths are non-negative.
      Parameters:
      u1 - the parameter at the first end point of a subpath
      u2 - the parameter at the second end point of a subpath
      Returns:
      the length of the subpath
      Throws:
      IllegalStateException - the path is not a simple path or the path was not set
      IllegalArgumentException - the parameter is out of bounds
      See Also:
    • getDistance

      public double getDistance(double u1, double u2) throws IllegalStateException, IllegalArgumentException
      Get the distance traversed on a subpath. If u2 < u1, the value returned is negative.

      This is intended for cases where direction is important.

      Parameters:
      u1 - the parameter at the first end point of a subpath
      u2 - the parameter at the second end point of a subpath
      Returns:
      the distance traversed on a subpath
      Throws:
      IllegalStateException - the path is not a simple path
      IllegalArgumentException - the parameter is out of bounds
    • s

      public double s(double u) throws IllegalStateException, IllegalArgumentException
      Get the distance along a path from its start for a specified path parameter.
      Parameters:
      u - the path parameter
      Returns:
      the distance along a path from its start
      Throws:
      IllegalStateException - the path was not set
      IllegalArgumentException
      See Also:
    • u

      public double u(double s) throws IllegalStateException, IllegalArgumentException
      Get the path parameter corresponding to a specified distance along a path from its start.
      Parameters:
      s - the distance along a path from its start
      Returns:
      the path parameter
      Throws:
      IllegalStateException - the path was not set
      IllegalArgumentException
      See Also:
    • setColor

      public void setColor(Color color)
      Set the color for a line drawing this path when addTo is called.
      Parameters:
      color - the color
    • getColor

      public Color getColor()
      Get the color for a line drawing this path when addTo is called.
      Returns:
      the color
    • setStroke

      public void setStroke(Stroke stroke)
      Set the stroke for a line drawing this path when addTo is called.
      Parameters:
      stroke - the stroke
    • getStroke

      public Stroke getStroke()
      Get the stroke for a line drawing this path when addTo is called.
      Returns:
      the stroke
    • setGcsMode

      public void setGcsMode(boolean gcsMode)
      Set GCS mode. When GCS mode is set the stroke's width and dash array are interpreted in graph coordinate space units; otherwise in user-space units (the default).
      Parameters:
      gcsMode - true if the stroke's units are in graph coordinate space units; false if they are in user space units.
    • getGcsMode

      public boolean getGcsMode()
      Get GCS mode. When GCS mode is set the stroke's width and dash array are interpreted in graph coordinate space units; otherwise in user-space units.
      Returns:
      true if in graph-coordinate-space mode; false if in user-space mode
    • showSegments

      public void showSegments(boolean mode, double radius)
      Configure this path so that it will draw the end of each path segment when visible and when GCS mode is false.
      Parameters:
      mode - true to draw the segment ends; false to just draw the path
      radius - the radius of a circle representing the end of a segment
    • addTo

      public void addTo(Graph graph, Graphics2D g2d, Graphics2D g2dgcs)
      Description copied from interface: Graph.Graphic
      Add this object to a graph. The drawing operation is assumed to be a complex one that might involve fills, etc.

      Any modifications to g2d or g2dGCS made by an implementation of this method should be undone before this method returns. For classes provided by the org.bzdev.anim2d package, such modifications must be undone before this method returns.

      Two graphics contexts are provided as arguments. g2d will typically be used as the first argument to the graph's draw or fill methods. In this case, the shape of an object is described in graph coordinate space but the widths of strokes drawn by fill operations, gradient paint, etc., have user-space units. The result is that line widths as they appear in an image are not sensitive to the mapping from graph coordinate space to user space. One should use the draw and fill methods specified by Graph, using g2d as their first argument. By contrast, if a line width, etc., should be in graph-coordinate space units, one can use the g2dGCS argument directly. This will rarely be done when plotting a graph but is useful in animations.

      Parameters:
      graph - the graph on which this object should be drawn
      g2d - the user-space Graphics2D to use to draw the Graphic
      g2dgcs - the graph-coordinate space Graphics2D to use to draw the Graphic
    • printConfiguration

      public void printConfiguration(String iPrefix, String prefix, boolean printName, PrintWriter out)
      Print this simulation object's configuration. Documentation for the use of this method is provided by the documentation for the SimObject method SimObject.printConfiguration(String,String,boolean,PrintWriter).

      When the second argument has a value of true, the object name and class name will be printed in a standard format with its indentation provided by the iPrefix argument. In addition, the configuration that is printed includes the following items.

      Defined in AnimationObject2D:

      • the Z-order.
      • whether or not this object is visible.
      Defined in AnimationPath2D:
      Overrides:
      printConfiguration in class AnimationObject2D
      Parameters:
      iPrefix - the prefix to use for an initial line when printName is true with null treated as an empty string
      prefix - a prefix string (typically whitespace) to put at the start of each line other than the initial line that is printed when printName is true
      printName - requests printing the name of an object
      out - the output print writer
    • clone

      protected Object clone() throws CloneNotSupportedException
      Creates and returns a copy of this object. This method will throw the exception CloneNotSupportedException if the object is interned.
      Overrides:
      clone in class Object
      Throws:
      CloneNotSupportedException - a clone could not be created
      See Also:
    • isInterned

      public boolean isInterned()
      Determine if an object is interned in a object namer's tables.
      Specified by:
      isInterned in interface NamedObjectOps
      Returns:
      true if the object is interned; false if not
    • getObjectNamer

      protected Simulation getObjectNamer()
      Get the object namer for a named object.
      Returns:
      the object namer for this named object
    • getName

      public final String getName()
      Get an object's name.
      Specified by:
      getName in interface NamedObjectOps
      Returns:
      the name of the object
    • canDelete

      public boolean canDelete()
      Determine if this named object can be deleted. A named object can be deleted if the method delete has not been called and if the object is not in a state that prevents the object from being deleted. Subclasses that override this method must call canDelete() for their superclasses and return false if the superclass' canDelete method returns false. The default method returns true if delete() has not been called and returned true.
      Specified by:
      canDelete in interface NamedObjectOps
      Returns:
      true if this object can be deleted; false otherwise
    • delete

      public final boolean delete()
      Delete an object. An object can only be deleted once. If this method returns true, the object (if interned) will have been removed from the object namer tables.

      The implementations provided by DefaultNamedObect and generated because of a @NamedObject annotation provide a protected method named onDelete. A subclass that overrides onDelete() must call the onDelete method of its superclass after it's onDelete method has been called and any cleanup actions performed. In some cases, this may happen at a later time (e.g., if a thread is used for some of the cleanup operations or if it is otherwise necessary to wait).

      Specified by:
      delete in interface NamedObjectOps
      Returns:
      true if the deletion request was accepted; false otherwise
    • isDeleted

      public final boolean isDeleted()
      Determine if an object has been deleted. An object is deleted if the method delete() has been called and returned true.
      Specified by:
      isDeleted in interface NamedObjectOps
      Returns:
      true if deleted; false otherwise
    • deletePending

      public final boolean deletePending()
      Determine if an object is being deleted. An deletion is pending if the method delete() has been called and returned true but the deletion has not been completed.
      Specified by:
      deletePending in interface NamedObjectOps
      Returns:
      true if deletion is pending; false otherwise