public class LineSegment extends Line
A line segment has two endpoints and lies on a line with the same slope. This class is a subclass of the Line class.
| Modifier and Type | Field and Description |
|---|---|
private Point |
p1
Point representing the first endpoint for the line segment
|
private Point |
p2
Point representing the second endpoint for the line segment
|
| Constructor and Description |
|---|
LineSegment(Point p1,
Point p2)
Constructor that accepts the two endpoints of the line segment.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
equals(java.lang.Object object)
Method to compare 'this' line segment for equality with the 'object' specified
as a parameter.
|
Point |
getP1()
Getter for the first endpoint
|
Point |
getP2()
Getter for the second endpoint
|
Point |
intersection(Line line)
A method that computes and returns the Point intersection of 'this' line segment and
the line specified in the parameter.
|
Point |
intersection(LineSegment lineSegment)
A method that computes and returns the Point of of intersection of 'this' line
segment and the line segment specified in the parameter.
|
double |
length()
Method to compute the length of 'this' line segment.
|
Point |
midpoint()
Method to compute the midpoint of 'this' line segment
|
boolean |
oneCommonEndpoint(LineSegment lineSegment)
Method that checks if 'this' line segment has one common end-point with the specified
line segment.
|
boolean |
pointIsOnLineSegment(Point p)
This method is called to find if the specified Point lies on 'this' line segment.
|
void |
setP1(Point p1)
Setter to change the first endpoint
|
void |
setP2(Point p2)
Setter to change the first endpoint
|
java.lang.String |
toString()
Method to render 'this' instance of the LineSegment class into a String.
|
getSlope, getyIntercept, isParallelTo, isPerpendicularTo, pointIsOnTheLine, setSlope, setyIntercept, updateLineprivate Point p1
private Point p2
public LineSegment(Point p1, Point p2)
p1 - Point representing one endpoint of the line segmentp2 - Point representing the other endpoint of the line segmentpublic Point getP1()
public void setP1(Point p1)
p1 - A Point representing the new first enpoint of the line segmentpublic Point getP2()
public void setP2(Point p2)
p2 - A Point representing the new first enpoint of the line segmentpublic boolean pointIsOnLineSegment(Point p)
p - The point we are checking to see if it lies on the 'this' line segment.public Point intersection(Line line)
intersection in class Lineline - The line for which we are computing the intersection with 'this'
line.public Point intersection(LineSegment lineSegment)
lineSegment - The line segment for which we are computing the intersection with
'this' line segment.public boolean oneCommonEndpoint(LineSegment lineSegment)
lineSegment - The line segment for which we are checking for a common end-point with
'this' line segment.public double length()
public Point midpoint()
public boolean equals(java.lang.Object object)