Class Trajectory3D
This class extends PolyLine3D by adding simple trajectory semantics:
points can be appended one at a time, the trajectory can be cleared, and an
optional maximum point count can be enforced.
Internally, the trajectory is stored as a flat coordinate array in the form:
[x1, y1, z1, x2, y2, z2, ..., xn, yn, zn]Consecutive points are connected by straight line segments when drawn.
If a maximum point count is specified and the trajectory exceeds that limit, the oldest point is discarded so that the most recent points remain visible. This implementation uses a simple array shift when discarding old points. That keeps the code straightforward and is usually adequate for demo-scale trajectories.
Allocation strategy
A single backing buffer is owned by this class and never exposed to
PolyLine3D's drawing path as a trimmed copy. Instead,
PolyLine3D.setCoords(float[], int) is used so the draw loop reads
only the live slice of the buffer, eliminating the per-append allocation that
the naive Arrays.copyOf approach would incur.
-
Field Summary
Fields inherited from class edu.cnu.mdi.mdi3D.item3D.Item3D
_panel3D, FILLALPHA, FILLCOLOR, FONT, LINE_WIDTH, LINEALPHA, LINECOLOR, TEXT_COLOR -
Constructor Summary
ConstructorsConstructorDescriptionTrajectory3D(Panel3D panel3D, Color color, float lineWidth) Creates an unbounded trajectory with a default initial capacity.Trajectory3D(Panel3D panel3D, Color color, float lineWidth, int maxPoints) Creates a trajectory with an optional maximum number of points.Trajectory3D(Panel3D panel3D, Color color, float lineWidth, int maxPoints, int initialCapacity) Creates a trajectory with full control over maximum point count and initial storage capacity. -
Method Summary
Modifier and TypeMethodDescriptionvoidappend(float[] xyz) Appends a new point to the end of the trajectory.voidappend(float x, float y, float z) Appends a new point to the end of the trajectory.voidclear()Removes all points from the trajectory.intGets the maximum allowed number of points.intGets the current number of points in the trajectory.booleanisEmpty()Checks whether the trajectory is empty.Methods inherited from class edu.cnu.mdi.mdi3D.item3D.PolyLine3D
draw, getCentroid, getCoords, getLivePoints, getSortPoint, setCoords, setCoordsMethods inherited from class edu.cnu.mdi.mdi3D.item3D.Item3D
addChild, defaultProperties, dispose, disposeItem, drawItem, get, getChildren, getColor, getFillAlpha, getFillColor, getFloat, getFont, getFont, getInt, getLineAlpha, getLineColor, getLineWidth, getPanel3D, getParent, getString, getTextColor, isVisible, put, removeChild, setAlphaOfColor, setFillAlpha, setFillColor, setFont, setLineAlpha, setLineColor, setLineWidth, setTextColor, setVisible
-
Constructor Details
-
Trajectory3D
Creates an unbounded trajectory with a default initial capacity.- Parameters:
panel3D- the owning 3D panelcolor- the trajectory colorlineWidth- the trajectory line width
-
Trajectory3D
Creates a trajectory with an optional maximum number of points.- Parameters:
panel3D- the owning 3D panelcolor- the trajectory colorlineWidth- the trajectory line widthmaxPoints- the maximum number of points to retain; values less than or equal to zero mean no explicit maximum
-
Trajectory3D
public Trajectory3D(Panel3D panel3D, Color color, float lineWidth, int maxPoints, int initialCapacity) Creates a trajectory with full control over maximum point count and initial storage capacity.- Parameters:
panel3D- the owning 3D panelcolor- the trajectory colorlineWidth- the trajectory line widthmaxPoints- the maximum number of points to retain; values less than or equal to zero mean no explicit maximuminitialCapacity- the initial storage capacity in points; values less than 2 are promoted to 2
-
-
Method Details
-
append
public void append(float x, float y, float z) Appends a new point to the end of the trajectory.If the trajectory has a fixed maximum size and is already full, the oldest point is discarded before the new point is appended. No allocation occurs unless the backing buffer needs to grow.
- Parameters:
x- the x coordinate of the new pointy- the y coordinate of the new pointz- the z coordinate of the new point
-
append
public void append(float[] xyz) Appends a new point to the end of the trajectory.- Parameters:
xyz- the point coordinates as[x, y, z]- Throws:
IllegalArgumentException- if the array isnullor has length less than 3
-
clear
public void clear()Removes all points from the trajectory.After calling this method, nothing will be drawn until at least two points have been appended. The backing buffer is retained so that a subsequent fill does not re-allocate.
-
getPointCount
public int getPointCount()Gets the current number of points in the trajectory.- Returns:
- the number of stored points
-
getMaxPoints
public int getMaxPoints()Gets the maximum allowed number of points.- Returns:
- the maximum number of points, or a value less than or equal to zero if the trajectory is unbounded
-
isEmpty
public boolean isEmpty()Checks whether the trajectory is empty.- Returns:
trueif no points are stored,falseotherwise
-