Class LineSegment3

java.lang.Object
com.ardor3d.math.Line3Base
com.ardor3d.math.LineSegment3
All Implemented Interfaces:
Poolable, ReadOnlyLine3Base, ReadOnlyLineSegment3, Savable, Externalizable, Serializable

public class LineSegment3 extends Line3Base implements ReadOnlyLineSegment3, Poolable
LineSegment describes a line with a discrete length with an "origin" in the center, extending in the given "direction" and it's opposite by an "extent" amount.
See Also:
  • Field Details

    • _extent

      protected double _extent
  • Constructor Details

    • LineSegment3

      public LineSegment3()
      Constructs a new segment segment with an origin at (0,0,0) a direction of (0,0,1) and an extent of 0.5.
    • LineSegment3

      public LineSegment3(ReadOnlyLineSegment3 source)
      Copy constructor.
      Parameters:
      source - the line segment to copy from.
    • LineSegment3

      public LineSegment3(ReadOnlyVector3 origin, ReadOnlyVector3 direction, double extent)
      Constructs a new segment segment using the supplied origin point, unit length direction vector and extent
      Parameters:
      origin - the origin
      direction - the direction vector - unit length
      extent - the extent
    • LineSegment3

      public LineSegment3(ReadOnlyVector3 start, ReadOnlyVector3 end)
      Constructs a new segment segment using the supplied start and end points
      Parameters:
      start - the start point
      end - the end point
  • Method Details

    • set

      public LineSegment3 set(ReadOnlyLineSegment3 source)
      Copies the values of the given source segment into this segment.
      Parameters:
      source - the line segment to copy from
      Returns:
      this segment for chaining
      Throws:
      NullPointerException - if source is null.
    • getExtent

      public double getExtent()
      Specified by:
      getExtent in interface ReadOnlyLineSegment3
      Returns:
      this segment's extent value
    • setExtent

      public void setExtent(double extent)
      Sets the segment's extent to the provided value.
      Parameters:
      extent - the extent
    • getPositiveEnd

      public Vector3 getPositiveEnd(Vector3 store)
    • getNegativeEnd

      public Vector3 getNegativeEnd(Vector3 store)
    • distanceSquared

      public double distanceSquared(ReadOnlyVector3 point, Vector3 store)
      Specified by:
      distanceSquared in interface ReadOnlyLine3Base
      Parameters:
      point - the point
      store - if not null, the closest point is stored in this param
      Returns:
      the squared distance from this segment to the given point.
      Throws:
      NullPointerException - if the point is null.
    • random

      public Vector3 random(Vector3 store)
      Parameters:
      store - the object to store the result if not null
      Returns:
      a random position lying somewhere on this line segment.
    • isValid

      public static boolean isValid(ReadOnlyLineSegment3 segment)
      Check a segment... if it is null or the values of its origin or direction or extent are NaN or infinite, return false. Else return true.
      Parameters:
      segment - the segment to check
      Returns:
      true or false as stated above.
    • toString

      public String toString()
      Overrides:
      toString in class Object
      Returns:
      the string representation of this segment.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
      Parameters:
      o - the object to compare for equality
      Returns:
      true if this segment and the provided segment have the same constant and normal values.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Line3Base
      Returns:
      returns a unique code for this segment object based on its values.
    • clone

      public LineSegment3 clone()
      Specified by:
      clone in interface ReadOnlyLineSegment3
      Overrides:
      clone in class Object
    • write

      public void write(OutputCapsule capsule) throws IOException
      Specified by:
      write in interface Savable
      Overrides:
      write in class Line3Base
      Throws:
      IOException
    • read

      public void read(InputCapsule capsule) throws IOException
      Specified by:
      read in interface Savable
      Overrides:
      read in class Line3Base
      Throws:
      IOException
    • readExternal

      public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
      Used with serialization. Not to be called manually.
      Specified by:
      readExternal in interface Externalizable
      Overrides:
      readExternal in class Line3Base
      Parameters:
      in - ObjectInput
      Throws:
      IOException - if something wrong occurs while reading
      ClassNotFoundException - if a class is not found
    • writeExternal

      public void writeExternal(ObjectOutput out) throws IOException
      Used with serialization. Not to be called manually.
      Specified by:
      writeExternal in interface Externalizable
      Overrides:
      writeExternal in class Line3Base
      Parameters:
      out - ObjectOutput
      Throws:
      IOException - if something wrong occurs while writing
    • fetchTempInstance

      public static final LineSegment3 fetchTempInstance()
      Returns:
      An instance of LineSegment3 that is intended for temporary use in calculations and so forth. Multiple calls to the method should return instances of this class that are not currently in use.
    • releaseTempInstance

      public static final void releaseTempInstance(LineSegment3 segment)
      Releases a LineSegment3 back to be used by a future call to fetchTempInstance. TAKE CARE: this LineSegment3 object should no longer have other classes referencing it or "Bad Things" will happen.
      Parameters:
      segment - the LineSegment3 to release.