- All Implemented Interfaces:
Graph.Graphic,NamedObjectOps
-
Constructor Summary
ConstructorsConstructorDescriptionAnimationPath2D(Animation2D animation, String name, boolean intern) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddTo(Graph graph, Graphics2D g2d, Graphics2D g2dgcs) Add this object to a graph.booleanDetermine if this named object can be deleted.protected Objectclone()Creates and returns a copy of this object.doublecurvature(double u) Compute the curvature given path parameter.doubled2xDu2(double u) Get the second derivative of the x coordinate with respect to the path parameter for a given value of the parameter.doubled2yDu2(double u) Get the second derivative of the y coordinate with respect to the path parameter.final booleandelete()Delete an object.final booleanDetermine if an object is being deleted.doubledsDu(double u) Get the derivative of the path length with respect to the path parameter for a given value of the parameter.doubledxDu(double u) Get the derivative of the x coordinate with respect to the path parameter for a given value of the parameter.doubledyDu(double u) Get the derivative of the y coordinate with respect to the path parameter.getColor()Get the color for a line drawing this path when addTo is called.doublegetDistance(double u1, double u2) Get the distance traversed on a subpath.booleanGet GCS mode.doubleGet the inversion limit for the path.doubleGet the maximum value of the path parameter.final StringgetName()Get an object's name.protected SimulationGet the object namer for a named object.getPath()Get the current path.doubleGet the total length of the path.doublegetPathLength(double u1, double u2) Get the length of a subpath.getPoint(double u) Get the point on a path corresponding to a given value of the path parameter.Get the stroke for a line drawing this path when addTo is called.doublegetX(double u) Get the x coordinate for a given value of the path parameter.doublegetY(double u) Get the y coordinate for a given value of the parameter.voidinitPath()Initialize the path with a default winding rule.booleanisClosed()Determine if the path is a closed path.final booleanDetermine if an object has been deleted.booleanDetermine if an object is interned in a object namer's tables.voidprintConfiguration(String iPrefix, String prefix, boolean printName, PrintWriter out) Print this simulation object's configuration.doubles(double u) Get the distance along a path from its start for a specified path parameter.voidSet the color for a line drawing this path when addTo is called.voidsetGcsMode(boolean gcsMode) Set GCS mode.voidsetInversionLimit(double limit) Set the inversion limit.voidsetPath(BasicSplinePath2D spath) Set the path.voidSet the stroke for a line drawing this path when addTo is called.voidshowSegments(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.doubleu(double s) Get the path parameter corresponding to a specified distance along a path from its start.Methods inherited from class org.bzdev.anim2d.AnimationObject2D
addToFrame, addToFrame, getAnimation, getZorder, isVisible, printState, setVisible, setZorder, setZorderMethods inherited from class org.bzdev.devqsim.SimObject
addSimulationListener, addTraceSet, bindCallable, bindCallable, bindCallable, bindCallable, bindRunnable, bindRunnable, bindRunnable, bindRunnable, callableObject, callableScript, callScriptFunction, callScriptMethod, clearTraceSets, evalScript, getEventListenerList, getScriptObject, getTraceSets, onDelete, printConfiguration, printConfiguration, printConfiguration, printConfiguration, printConfiguration, printConfiguration, printState, printState, printState, printState, printState, printState, putScriptObject, removeSimulationListener, removeTraceSet, runnableObject, runnableScript, scheduleCall, scheduleCall, scheduleCall, scheduleCall, scheduleCallObject, scheduleScript, scheduleTask, scheduleTask, scheduleTask, scheduleTask, scheduleTaskObject, scheduleTaskScript, startImmediateTask, startImmediateTask, trace, trace, unscheduledTaskThread, unscheduledTaskThread, update, update, usesTraceSetMethods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.bzdev.graphs.Graph.Graphic
boundingBoxMethods inherited from interface org.bzdev.obnaming.NamedObjectOps
canDelete, delete, deletePending, getName, isDeleted, isInterned
-
Constructor Details
-
AnimationPath2D
Constructor.- Parameters:
animation- the animationname- the name of the object; null for an automatically generated nameintern- true if the object can be looked up by using the methods inSimulation; false otherwise.- Throws:
IllegalArgumentException- typically means a name is already in use- See Also:
-
-
Method Details
-
setPath
Set the path.- Parameters:
spath- the path
-
initPath
public void initPath()Initialize the path with a default winding rule. -
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
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 setIllegalArgumentException- the parameter is out of bounds- See Also:
-
getY
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 setIllegalArgumentException- the parameter is out of bounds- See Also:
-
getPoint
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 setIllegalArgumentException- the parameter is out of bounds- See Also:
-
dxDu
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 setIllegalArgumentException- the parameter is out of bounds- See Also:
-
dyDu
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 setIllegalArgumentException- the parameter is out of bounds- See Also:
-
d2xDu2
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 setIllegalArgumentException- the parameter is out of bounds- See Also:
-
d2yDu2
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 setIllegalArgumentException- the parameter is out of bounds- See Also:
-
curvature
Compute the curvature given path parameter. The curvature is given by the expression
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.(x'y" - y'x")/(xp2 + y'2)3/2- Parameters:
u- the path-segment parameter- Returns:
- the curvature
- Throws:
IllegalStateException- the path is not a simple path or the path was not setIllegalArgumentException- the parameter is out of bounds- See Also:
-
dsDu
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 setIllegalArgumentException- 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
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 setIllegalArgumentException- 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 subpathu2- 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 setIllegalArgumentException- 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 subpathu2- 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 pathIllegalArgumentException- the parameter is out of bounds
-
s
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 setIllegalArgumentException- See Also:
-
u
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 setIllegalArgumentException- See Also:
-
setColor
Set the color for a line drawing this path when addTo is called.- Parameters:
color- the color
-
getColor
Get the color for a line drawing this path when addTo is called.- Returns:
- the color
-
setStroke
Set the stroke for a line drawing this path when addTo is called.- Parameters:
stroke- the 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 pathradius- the radius of a circle representing the end of a segment
-
addTo
Description copied from interface:Graph.GraphicAdd 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 drawng2d- the user-space Graphics2D to use to draw the Graphicg2dgcs- the graph-coordinate space Graphics2D to use to draw the Graphic
-
printConfiguration
Print this simulation object's configuration. Documentation for the use of this method is provided by the documentation for theSimObjectmethodSimObject.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.
AnimationPath2D:- the configuration for a BasicSplinePath2D, provided by
calling this path's method
BasicSplinePath2D.printTable(String,Appendable).
- Overrides:
printConfigurationin classAnimationObject2D- Parameters:
iPrefix- the prefix to use for an initial line when printName is true with null treated as an empty stringprefix- a prefix string (typically whitespace) to put at the start of each line other than the initial line that is printed when printName is trueprintName- requests printing the name of an objectout- the output print writer
-
clone
Creates and returns a copy of this object. This method will throw the exception CloneNotSupportedException if the object is interned.- Overrides:
clonein classObject- 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:
isInternedin interfaceNamedObjectOps- Returns:
- true if the object is interned; false if not
-
getObjectNamer
Get the object namer for a named object.- Returns:
- the object namer for this named object
-
getName
Get an object's name.- Specified by:
getNamein interfaceNamedObjectOps- 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:
canDeletein interfaceNamedObjectOps- 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
DefaultNamedObectand generated because of a@NamedObjectannotation 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:
deletein interfaceNamedObjectOps- 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:
isDeletedin interfaceNamedObjectOps- 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:
deletePendingin interfaceNamedObjectOps- Returns:
- true if deletion is pending; false otherwise
-