|
Algorithm Development Kit 1.0 |
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectalgs.model.twod.TwoDLineSegment
public class TwoDLineSegment
Standard two-dimensional implementation of ILineSegment. By etiquette, all line segments are directionless, so we impose our own order on things. Specifically, the start of the line has its y value >= the y-value of the end.
| Field Summary | |
|---|---|
TwoDPoint |
end
Store Line segment end. |
boolean |
isPoint
Is just a point? |
double |
m
Slope. |
int |
sign
Sign of Slope. |
TwoDPoint |
start
Store Line segment start. |
| Fields inherited from interface algs.model.ILineSegment |
|---|
COINCIDENT, INTERSECTING, NON_INTERSECTING, PARALLEL |
| Constructor Summary | |
|---|---|
TwoDLineSegment(double x1,
double y1,
double x2,
double y2)
Helper method for constructing a Line segment from four points. |
|
TwoDLineSegment(IPoint s,
IPoint e)
|
|
| Method Summary | |
|---|---|
int |
dimensionality()
Return the dimensionality of this line segment. |
boolean |
equals(java.lang.Object o)
Provides the standard equals method. |
IPoint |
getEnd()
Return the coordinate value of the End of the line segment as a two-dimensional IPoint. |
IMultiPoint |
getEndPoint()
Return the coordinate value of the End of the line segment as an IMultiPoint. |
IPoint |
getStart()
Return the coordinate value of the Start of the line segment as a two-dimensional IPoint. |
IMultiPoint |
getStartPoint()
Return the coordinate value of the Start of the line segment as an IMultiPoint. |
IPoint |
intersection(ILineSegment other)
Computer the intersection point with the given line segment. |
boolean |
intersection(IPoint p)
Determine if line segments intersects this point. |
int |
intersectionType(ILineSegment other)
Compute the intersection type with the given line segment. |
boolean |
isHorizontal()
Determine if horizontal. |
boolean |
isPoint()
Determine if this line segment is simply a point (same start & end). |
boolean |
isVertical()
Determine if vertical. |
boolean |
pointOnLeft(IPoint p)
Given the line segment in its reverse-directed orientation (from lower to upper point), determine if point p is to the left of the line, as you head from lower to upper If it is exactly on the line, then we return false. |
boolean |
pointOnRight(IPoint p)
Given the line segment in its reverse-directed orientation (from lower to upper point), determine if point p is to the right of the line, as you head from lower to upper. |
int |
sign()
Return sign of slope. |
double |
slope()
Compute slope of line segment, or return Double.NaN for vertical lines. |
java.lang.String |
toString()
Reasonable toString() implementation. |
double |
yIntercept()
Compute yIntercept of line segment if extended to be a line. |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public final TwoDPoint start
public final TwoDPoint end
public final boolean isPoint
public final double m
public final int sign
| Constructor Detail |
|---|
public TwoDLineSegment(double x1,
double y1,
double x2,
double y2)
x1 - x-value of p1y1 - y-value of p1x2 - x-value of p2y2 - y-value of p2
public TwoDLineSegment(IPoint s,
IPoint e)
s - Start of this line segment in two-dimensional spacee - End of this line segment in two-dimensional space
TODO: Should we prevent attempts to store with Infinity?| Method Detail |
|---|
public IMultiPoint getStartPoint()
IMultiLineSegment
getStartPoint in interface IMultiLineSegmentIMultiLineSegment.getStartPoint()public IMultiPoint getEndPoint()
IMultiLineSegment
getEndPoint in interface IMultiLineSegmentIMultiLineSegment.getEndPoint()public IPoint getStart()
ILineSegment
getStart in interface ILineSegmentILineSegment.getStart()public IPoint getEnd()
ILineSegment
getEnd in interface ILineSegmentILineSegment.getEnd()public boolean equals(java.lang.Object o)
equals in class java.lang.Objectpublic java.lang.String toString()
toString in class java.lang.Objectpublic int dimensionality()
IMultiLineSegment
dimensionality in interface IMultiLineSegmentIMultiLineSegment.dimensionality()public double slope()
slope in interface ILineSegmentpublic int sign()
sign in interface ILineSegmentpublic boolean isHorizontal()
isHorizontal in interface ILineSegmentpublic boolean isVertical()
isVertical in interface ILineSegmentpublic double yIntercept()
yIntercept in interface ILineSegmentpublic int intersectionType(ILineSegment other)
other - other line segment with which to compare.public IPoint intersection(ILineSegment other)
intersection in interface ILineSegmentpublic boolean intersection(IPoint p)
Intersection is true if point equals either of the end points. Removed since it detects intersections along the infinite line which is the extension of this line segment. Only for vertical lines does this method restrict the intersection to between (start, end).
intersection in interface ILineSegmentp - point to be inspected.public boolean isPoint()
ILineSegment
isPoint in interface ILineSegmentILineSegment.isPoint()public boolean pointOnRight(IPoint p)
(y2 - y1)
0 = y - y1 - --------- (x - x1)
(x2 - x1)
Since this operation is SO COMMON, we use a standard trick to remove the IF statements.
Specifically, if m is positive, then we check if res < 0 but if m is negative, then we
check if -res < 0. Thus we also need to store the SIGN of the slope with each segment.
pointOnRight in interface ILineSegmentp - Point in questionpublic boolean pointOnLeft(IPoint p)
pointOnRight(IPoint) for the mathematical explanation
for these equations, as well as importance of sign.
pointOnLeft in interface ILineSegmentp -
|
Algorithm Development Kit 1.0 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||