rcssjava.geom
Class LineSegment

java.lang.Object
  extended by rcssjava.geom.LineSegment

public class LineSegment
extends java.lang.Object

Implementation of 2d line segment


Constructor Summary
LineSegment()
          Constructs a line segment with both endpoints at the origin
LineSegment(VecPosition p1, VecPosition p2)
          Constructs a line segment with the given endpoints
 
Method Summary
 Rectangle getBoundingRectangle()
          Create the rectangle that has this line segment as a diagonal
 VecPosition getIntersection(Line l)
          Get intersection with line
 VecPosition getIntersection(LineSegment ls)
          Get intersection with line segment
 double getLength()
          Get distance between endpoints
 Line getLine()
          Create infinite line from this segment
 VecPosition getMidpoint()
          Get point on line segment halfway between endpoints
 void setPoints(VecPosition p1, VecPosition p2)
          Set endpoints of line segment
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LineSegment

public LineSegment()
Constructs a line segment with both endpoints at the origin


LineSegment

public LineSegment(VecPosition p1,
                   VecPosition p2)
Constructs a line segment with the given endpoints

Parameters:
p1 - first endpoint
p2 - second endpoint
Method Detail

setPoints

public void setPoints(VecPosition p1,
                      VecPosition p2)
Set endpoints of line segment

Parameters:
p1 - first endpoint
p2 - second endpoint

getLength

public double getLength()
Get distance between endpoints

Returns:
euclidean distance between endpoints

getMidpoint

public VecPosition getMidpoint()
Get point on line segment halfway between endpoints

Returns:
midpoint

getBoundingRectangle

public Rectangle getBoundingRectangle()
Create the rectangle that has this line segment as a diagonal

Returns:
bounding rectangle

getLine

public Line getLine()
Create infinite line from this segment

Returns:
extrapolated line

getIntersection

public VecPosition getIntersection(Line l)
Get intersection with line

Parameters:
l - line to intersect with
Returns:
intersection point or null if none

getIntersection

public VecPosition getIntersection(LineSegment ls)
Get intersection with line segment

Parameters:
ls - line segment to intersect with
Returns:
intersection point or null if none