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 Summary
ConstructorDescriptionInstantiate 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 Summary
Modifier and TypeMethodDescriptionclone()
Create a copy of this segment.float
distance
(LineSegment ls) Calculate the distance between this segment and another.float
Calculate the distance between this segment and the specified Ray.float
Calculate the distance between this segment and the specified point.float
distanceSquared
(LineSegment test) Calculate the squared distance between this segment and another.float
Calculate the squared distance between this segment and the specified Ray.float
distanceSquared
(Vector3f point) Calculate the squared distance between this segment and the specified point.Access the direction of this segment.float
Read 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.boolean
isPointInsideBounds
(Vector3f point) /**boolean
isPointInsideBounds
(Vector3f point, float error) Evaluates whether a given point is contained within the axis aligned bounding box that contains this LineSegment.void
read
(JmeImporter importer) De-serialize this segment from the specified importer, for example when loading from a J3O file.void
set
(LineSegment ls) Copy the specified segment to this one.void
setDirection
(Vector3f direction) Alter the direction of this segment.void
setExtent
(float extent) Alter the extent of this segment.void
Alter the origin of this segment.toString()
Returns a string representation of the LineSegment, which is unaffected.void
write
(JmeExporter e) Serialize this segment to the specified exporter, for example when saving to a J3O file.
-
Constructor Details
-
LineSegment
public LineSegment()Instantiate a zero-length segment at the origin. -
LineSegment
Instantiate a copy of the specified segment.- Parameters:
ls
- the LineSegment to copy (not null, unaffected)
-
LineSegment
Creates 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
-
LineSegment
Creates 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
-
set
Copy the specified segment to this one.- Parameters:
ls
- the LineSegment to copy (not null, unaffected)
-
distance
Calculate the distance between this segment and the specified point.- Parameters:
point
- a location vector (not null, unaffected)- Returns:
- the minimum distance (≥0)
-
distance
Calculate the distance between this segment and another.- Parameters:
ls
- the other LineSegment (not null, unaffected)- Returns:
- the minimum distance (≥0)
-
distance
Calculate the distance between this segment and the specified Ray.- Parameters:
r
- the input Ray (not null, unaffected)- Returns:
- the minimum distance (≥0)
-
distanceSquared
Calculate 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)
-
distanceSquared
Calculate the squared distance between this segment and another.- Parameters:
test
- the other LineSegment (not null, unaffected)- Returns:
- the square of the minimum distance (≥0)
-
distanceSquared
Calculate 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)
-
getDirection
Access the direction of this segment.- Returns:
- the pre-existing direction vector
-
setDirection
Alter the direction of this segment.- Parameters:
direction
- the desired direction vector (alias created!)
-
getExtent
public float getExtent()Read the extent of this segment.- Returns:
- the extent
-
setExtent
public void setExtent(float extent) Alter the extent of this segment.- Parameters:
extent
- the desired extent
-
getOrigin
Access the origin of this segment.- Returns:
- the pre-existing location vector
-
setOrigin
Alter the origin of this segment.- Parameters:
origin
- the desired location vector (alias created!)
-
getPositiveEnd
Determine 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)
-
getNegativeEnd
Determine 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)
-
write
Serialize this segment to the specified exporter, for example when saving to a J3O file.- Specified by:
write
in interfaceSavable
- Parameters:
e
- (not null)- Throws:
IOException
- from the exporter
-
read
De-serialize this segment from the specified importer, for example when loading from a J3O file.- Specified by:
read
in interfaceSavable
- Parameters:
importer
- (not null)- Throws:
IOException
- from the importer
-
clone
Create a copy of this segment. -
toString
Returns 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
-
isPointInsideBounds
Evaluates 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
-