com.jme.math
Class LineSegment

java.lang.Object
  extended by com.jme.math.LineSegment
All Implemented Interfaces:
Savable, java.io.Serializable, java.lang.Cloneable

public class LineSegment
extends java.lang.Object
implements java.io.Serializable, java.lang.Cloneable, Savable

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.

Author:
Mark Powell, Joshua Slack
See Also:
Ray, Serialized Form

Constructor Summary
LineSegment()
           
LineSegment(LineSegment ls)
           
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
 LineSegment clone()
           
 float distance(LineSegment ls)
           
 float distance(Ray r)
           
 float distance(Vector3f point)
           
 float distanceSquared(LineSegment test)
           
 float distanceSquared(Ray r)
           
 float distanceSquared(Vector3f point)
           
 java.lang.Class<? extends LineSegment> getClassTag()
           
 Vector3f getDirection()
           
 float getExtent()
           
 Vector3f getNegativeEnd(Vector3f store)
           
 Vector3f getOrigin()
           
 Vector3f getPositiveEnd(Vector3f store)
           
 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 e)
           
 void set(LineSegment ls)
           
 void setDirection(Vector3f direction)
           
 void setExtent(float extent)
           
 void setOrigin(Vector3f origin)
           
 void write(JMEExporter e)
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LineSegment

public LineSegment()

LineSegment

public LineSegment(LineSegment ls)

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.


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.

Method Detail

set

public void set(LineSegment ls)

distance

public float distance(Vector3f point)

distance

public float distance(LineSegment ls)

distance

public float distance(Ray r)

distanceSquared

public float distanceSquared(Vector3f point)

distanceSquared

public float distanceSquared(LineSegment test)

distanceSquared

public float distanceSquared(Ray r)

getDirection

public Vector3f getDirection()

setDirection

public void setDirection(Vector3f direction)

getExtent

public float getExtent()

setExtent

public void setExtent(float extent)

getOrigin

public Vector3f getOrigin()

setOrigin

public void setOrigin(Vector3f origin)

getPositiveEnd

public Vector3f getPositiveEnd(Vector3f store)

getNegativeEnd

public Vector3f getNegativeEnd(Vector3f store)

write

public void write(JMEExporter e)
           throws java.io.IOException
Specified by:
write in interface Savable
Throws:
java.io.IOException

read

public void read(JMEImporter e)
          throws java.io.IOException
Specified by:
read in interface Savable
Throws:
java.io.IOException

getClassTag

public java.lang.Class<? extends LineSegment> getClassTag()
Specified by:
getClassTag in interface Savable

clone

public LineSegment clone()
Overrides:
clone in class java.lang.Object

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.


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.