Package com.jme3.math

# Class LineSegment

java.lang.Object
com.jme3.math.LineSegment
All Implemented Interfaces:
`Savable`, `Serializable`, `Cloneable`

public class LineSegment extends Object implements Cloneable, Savable, 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.

See Also:
• ## Constructor Summary

Constructors
Constructor
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.
• ## Method Summary

Modifier and Type
Method
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.

### Methods inherited from class java.lang.Object

`equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`
• ## Constructor Details

• ### LineSegment

public LineSegment()
Instantiate a zero-length segment at the origin.
• ### LineSegment

public LineSegment(LineSegment ls)
Instantiate a copy of the specified segment.
Parameters:
`ls` - the LineSegment to copy (not null, unaffected)
• ### LineSegment

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.

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

public 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.

Parameters:
`start` - location of the negative endpoint (not null, unaffected)
`end` - location of the negative endpoint (not null, unaffected)
• ## Method Details

• ### set

public void set(LineSegment ls)
Copy the specified segment to this one.
Parameters:
`ls` - the LineSegment to copy (not null, unaffected)
• ### distance

public float distance(Vector3f point)
Calculate the distance between this segment and the specified point.
Parameters:
`point` - a location vector (not null, unaffected)
Returns:
the minimum distance (≥0)
• ### distance

public float distance(LineSegment ls)
Calculate the distance between this segment and another.
Parameters:
`ls` - the other LineSegment (not null, unaffected)
Returns:
the minimum distance (≥0)
• ### distance

public float distance(Ray r)
Calculate the distance between this segment and the specified Ray.
Parameters:
`r` - the input Ray (not null, unaffected)
Returns:
the minimum distance (≥0)
• ### distanceSquared

public float distanceSquared(Vector3f point)
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

public float distanceSquared(LineSegment test)
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

public float distanceSquared(Ray r)
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

public Vector3f getDirection()
Access the direction of this segment.
Returns:
the pre-existing direction vector
• ### setDirection

public void setDirection(Vector3f direction)
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

public Vector3f getOrigin()
Access the origin of this segment.
Returns:
the pre-existing location vector
• ### setOrigin

public void setOrigin(Vector3f origin)
Alter the origin of this segment.
Parameters:
`origin` - the desired location vector (alias created!)
• ### getPositiveEnd

public Vector3f getPositiveEnd(Vector3f store)
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

public Vector3f getNegativeEnd(Vector3f store)
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

public void write(JmeExporter e) throws IOException
Serialize this segment to the specified exporter, for example when saving to a J3O file.
Specified by:
`write` in interface `Savable`
Parameters:
`e` - (not null)
Throws:
`IOException` - from the exporter
• ### read

public void read(JmeImporter importer) throws IOException
De-serialize this segment from the specified importer, for example when loading from a J3O file.
Specified by:
`read` in interface `Savable`
Parameters:
`importer` - (not null)
Throws:
`IOException` - from the importer
• ### clone

public LineSegment clone()
Create a copy of this segment.
Overrides:
`clone` in class `Object`
Returns:
a new instance, equivalent to this one
• ### isPointInsideBounds

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.

Parameters:
`point` - the location of the input point (not null, unaffected)
Returns:
true if contained in the box, otherwise false
• ### isPointInsideBounds

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.

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