Class LineSegment
- All Implemented Interfaces:
- Savable,- Serializable,- Cloneable
LineSegment represents a segment in the space. This is a portion of a Line that has a limited start and end points.
A LineSegment is defined by an origin, a direction and an extent (or length). Direction should be a normalized vector. It is not internally normalized.
This class provides methods to calculate distances between LineSegments, Rays and Vectors.
 It is also possible to retrieve both end points of the segment getPositiveEnd(Vector3f)
 and getNegativeEnd(Vector3f). There are also methods to check whether
 a point is within the segment bounds.
- See Also:
- 
Constructor SummaryConstructorsConstructorDescriptionInstantiate a zero-length segment at the origin.Instantiate a copy of the specified segment.LineSegment(Vector3f start, Vector3f end) Creates a new LineSegment with a given origin and end.LineSegment(Vector3f origin, Vector3f direction, float extent) Creates a new LineSegment with the given origin, direction and extent.
- 
Method SummaryModifier and TypeMethodDescriptionclone()Create a copy of this segment.floatdistance(LineSegment ls) Calculate the distance between this segment and another.floatCalculate the distance between this segment and the specified Ray.floatCalculate the distance between this segment and the specified point.floatdistanceSquared(LineSegment test) Calculate the squared distance between this segment and another.floatCalculate the squared distance between this segment and the specified Ray.floatdistanceSquared(Vector3f point) Calculate the squared distance between this segment and the specified point.Access the direction of this segment.floatRead the extent of this segment.getNegativeEnd(Vector3f store) Determine the location of this segment's negative end.Access the origin of this segment.getPositiveEnd(Vector3f store) Determine the location of this segment's positive end.booleanisPointInsideBounds(Vector3f point) /**booleanisPointInsideBounds(Vector3f point, float error) Evaluates whether a given point is contained within the axis aligned bounding box that contains this LineSegment.voidread(JmeImporter importer) De-serialize this segment from the specified importer, for example when loading from a J3O file.voidset(LineSegment ls) Copy the specified segment to this one.voidsetDirection(Vector3f direction) Alter the direction of this segment.voidsetExtent(float extent) Alter the extent of this segment.voidAlter the origin of this segment.toString()Returns a string representation of the LineSegment, which is unaffected.voidwrite(JmeExporter e) Serialize this segment to the specified exporter, for example when saving to a J3O file.
- 
Constructor Details- 
LineSegmentpublic LineSegment()Instantiate a zero-length segment at the origin.
- 
LineSegmentInstantiate a copy of the specified segment.- Parameters:
- ls- the LineSegment to copy (not null, unaffected)
 
- 
LineSegmentCreates a new LineSegment with the given origin, direction and extent. Note that the origin is not one of the ends of the LineSegment, but its center. - Parameters:
- origin- the location of the desired midpoint (alias created)
- direction- the desired direction vector (alias created)
- extent- the extent: 1/2 of the desired length, assuming direction is a unit vector
 
- 
LineSegmentCreates a new LineSegment with a given origin and end. This constructor will calculate the center, the direction and the extent. - Parameters:
- start- location of the negative endpoint (not null, unaffected)
- end- location of the negative endpoint (not null, unaffected)
 
 
- 
- 
Method Details- 
setCopy the specified segment to this one.- Parameters:
- ls- the LineSegment to copy (not null, unaffected)
 
- 
distanceCalculate the distance between this segment and the specified point.- Parameters:
- point- a location vector (not null, unaffected)
- Returns:
- the minimum distance (≥0)
 
- 
distanceCalculate the distance between this segment and another.- Parameters:
- ls- the other LineSegment (not null, unaffected)
- Returns:
- the minimum distance (≥0)
 
- 
distanceCalculate the distance between this segment and the specified Ray.- Parameters:
- r- the input Ray (not null, unaffected)
- Returns:
- the minimum distance (≥0)
 
- 
distanceSquaredCalculate the squared distance between this segment and the specified point.- Parameters:
- point- location vector of the input point (not null, unaffected)
- Returns:
- the square of the minimum distance (≥0)
 
- 
distanceSquaredCalculate the squared distance between this segment and another.- Parameters:
- test- the other LineSegment (not null, unaffected)
- Returns:
- the square of the minimum distance (≥0)
 
- 
distanceSquaredCalculate the squared distance between this segment and the specified Ray.- Parameters:
- r- the input Ray (not null, unaffected)
- Returns:
- the square of the minimum distance (≥0)
 
- 
getDirectionAccess the direction of this segment.- Returns:
- the pre-existing direction vector
 
- 
setDirectionAlter the direction of this segment.- Parameters:
- direction- the desired direction vector (alias created!)
 
- 
getExtentpublic float getExtent()Read the extent of this segment.- Returns:
- the extent
 
- 
setExtentpublic void setExtent(float extent) Alter the extent of this segment.- Parameters:
- extent- the desired extent
 
- 
getOriginAccess the origin of this segment.- Returns:
- the pre-existing location vector
 
- 
setOriginAlter the origin of this segment.- Parameters:
- origin- the desired location vector (alias created!)
 
- 
getPositiveEndDetermine the location of this segment's positive end.- Parameters:
- store- storage for the result (modified if not null)
- Returns:
- a location vector (either store or a new vector)
 
- 
getNegativeEndDetermine the location of this segment's negative end.- Parameters:
- store- storage for the result (modified if not null)
- Returns:
- a location vector (either store or a new vector)
 
- 
writeSerialize this segment to the specified exporter, for example when saving to a J3O file.- Specified by:
- writein interface- Savable
- Parameters:
- e- (not null)
- Throws:
- IOException- from the exporter
 
- 
readDe-serialize this segment from the specified importer, for example when loading from a J3O file.- Specified by:
- readin interface- Savable
- Parameters:
- importer- (not null)
- Throws:
- IOException- from the importer
 
- 
cloneCreate a copy of this segment.
- 
toStringReturns a string representation of the LineSegment, which is unaffected. For example, a segment extending from (1,0,0) to (1,1,0) is represented by:LineSegment [Origin: (1.0, 0.0, 0.0) Direction: (0.0, 1.0, 0.0) Extent: 1.0] 
- 
isPointInsideBounds/**Evaluates whether a given point is contained within the axis aligned bounding box that contains this LineSegment. This function is float error aware. - Parameters:
- point- the location of the input point (not null, unaffected)
- Returns:
- true if contained in the box, otherwise false
 
- 
isPointInsideBoundsEvaluates whether a given point is contained within the axis aligned bounding box that contains this LineSegment. This function accepts an error parameter, which is added to the extent of the bounding box. - Parameters:
- point- the location of the input point (not null, unaffected)
- error- the desired margin for error
- Returns:
- true if contained in the box, otherwise false
 
 
-