public class LineSegment extends java.lang.Object implements java.lang.Cloneable, Savable, java.io.Serializable
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.
Ray
,
Serialized FormConstructor and Description |
---|
LineSegment()
Instantiate a zero-length segment at the origin.
|
LineSegment(LineSegment ls)
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.
|
Modifier and Type | Method and Description |
---|---|
LineSegment |
clone()
Create a copy of this segment.
|
float |
distance(LineSegment ls)
Calculate the distance between this segment and another.
|
float |
distance(Ray r)
Calculate the distance between this segment and the specified Ray.
|
float |
distance(Vector3f point)
Calculate the distance between this segment and the specified point.
|
float |
distanceSquared(LineSegment test)
Calculate the squared distance between this segment and another.
|
float |
distanceSquared(Ray r)
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.
|
Vector3f |
getDirection()
Access the direction of this segment.
|
float |
getExtent()
Read the extent of this segment.
|
Vector3f |
getNegativeEnd(Vector3f store)
Determine the location of this segment's negative end.
|
Vector3f |
getOrigin()
Access the origin of this segment.
|
Vector3f |
getPositiveEnd(Vector3f store)
Determine the location of this segment's positive end.
|
boolean |
isPointInsideBounds(Vector3f point)
Evaluates whether a given point is contained within the axis aligned bounding box
that contains this LineSegment.
|
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 |
setOrigin(Vector3f origin)
Alter the origin of this segment.
|
void |
write(JmeExporter e)
Serialize this segment to the specified exporter, for example when
saving to a J3O file.
|
public LineSegment()
public LineSegment(LineSegment ls)
ls
- the LineSegment to copy (not null, unaffected)public LineSegment(Vector3f origin, Vector3f direction, float extent)
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.
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 vectorpublic LineSegment(Vector3f start, Vector3f end)
Creates a new LineSegment with a given origin and end. This constructor will calculate the center, the direction and the extent.
start
- location of the negative endpoint (not null, unaffected)end
- location of the negative endpoint (not null, unaffected)public void set(LineSegment ls)
ls
- the LineSegment to copy (not null, unaffected)public float distance(Vector3f point)
point
- a location vector (not null, unaffected)public float distance(LineSegment ls)
ls
- the other LineSegment (not null, unaffected)public float distance(Ray r)
r
- the input Ray (not null, unaffected)public float distanceSquared(Vector3f point)
point
- location vector of the input point (not null, unaffected)public float distanceSquared(LineSegment test)
test
- the other LineSegment (not null, unaffected)public float distanceSquared(Ray r)
r
- the input Ray (not null, unaffected)public Vector3f getDirection()
public void setDirection(Vector3f direction)
direction
- the desired direction vector (alias created!)public float getExtent()
public void setExtent(float extent)
extent
- the desired extentpublic Vector3f getOrigin()
public void setOrigin(Vector3f origin)
origin
- the desired location vector (alias created!)public Vector3f getPositiveEnd(Vector3f store)
store
- storage for the result (modified if not null)public Vector3f getNegativeEnd(Vector3f store)
store
- storage for the result (modified if not null)public void write(JmeExporter e) throws java.io.IOException
public void read(JmeImporter importer) throws java.io.IOException
public LineSegment clone()
clone
in class java.lang.Object
public boolean isPointInsideBounds(Vector3f point)
Evaluates whether a given point is contained within the axis aligned bounding box that contains this LineSegment.
This function is float error aware.
point
- the location of the input point (not null, unaffected)public boolean isPointInsideBounds(Vector3f point, float error)
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.
point
- the location of the input point (not null, unaffected)error
- the desired margin for error