Class PolyLine3D

java.lang.Object
edu.cnu.mdi.mdi3D.item3D.Item3D
edu.cnu.mdi.mdi3D.item3D.PolyLine3D
Direct Known Subclasses:
Trajectory3D

public class PolyLine3D extends Item3D
A 3D polyline item represented by an ordered list of vertices.

The coordinates are stored in the form:

 [x1, y1, z1, x2, y2, z2, ..., xn, yn, zn]
 
Consecutive points are connected by straight line segments, producing a single open polyline. This item is useful for drawing trajectories, orbit paths, field lines, and other connected 3D curves.

At least two points are required for visible output.

  • Constructor Details

    • PolyLine3D

      public PolyLine3D(Panel3D panel3D, float[] coords, Color color, float lineWidth)
      Creates a 3D polyline from an array of coordinates.
      Parameters:
      panel3D - the owning 3D panel
      coords - the polyline coordinates as [x1, y1, z1, ..., xn, yn, zn]
      color - the line color
      lineWidth - the line width
  • Method Details

    • draw

      public void draw(com.jogamp.opengl.GLAutoDrawable drawable)
      Draws the polyline.

      If there are fewer than two live points, nothing is drawn.

      Specified by:
      draw in class Item3D
      Parameters:
      drawable - the OpenGL drawable
    • setCoords

      public void setCoords(float[] coords)
      Replaces the coordinates of this polyline.

      The entire array is treated as live data; _livePoints is set to coords.length / 3. Pass null or an empty array to produce no output.

      Parameters:
      coords - the new coordinates as [x1, y1, z1, ..., xn, yn, zn], or null to clear
    • setCoords

      public void setCoords(float[] buf, int livePoints)
      Points this polyline at a (possibly oversized) buffer, treating only the first livePoints entries as valid data.

      No copy is made. The caller must not modify indices at or beyond 3 * livePoints while a draw is in progress. Trajectory3D satisfies this by writing new data only after advancing _pointCount.

      Parameters:
      buf - the coordinate buffer; must have length ≥ 3 * livePoints
      livePoints - number of valid points in buf; must be ≥ 0
      Throws:
      IllegalArgumentException - if livePoints is negative or the buffer is too small
    • getCoords

      public float[] getCoords()
      Gets the current coordinate buffer.

      The buffer may be larger than the live data; use getLivePoints() to determine how many points are valid.

      Returns:
      the coordinate buffer, or null if none has been set
    • getLivePoints

      public int getLivePoints()
      Returns the number of live points currently held by this polyline.
      Returns:
      number of valid points in the coordinate buffer
    • getCentroid

      public float[] getCentroid()
      Gets the centroid of the live polyline vertices.

      This is used as a representative point for sorting.

      Returns:
      the centroid of the live vertices, or the origin if there are none
    • getSortPoint

      public float[] getSortPoint()
      Gets a representative point used for item sorting.
      Overrides:
      getSortPoint in class Item3D
      Returns:
      the centroid of the live polyline vertices