public class LineSeg
extends java.lang.Object
implements java.io.Serializable, org.eclipse.draw2d.geometry.Translatable
| Modifier and Type | Class and Description |
|---|---|
static class |
LineSeg.KeyPoint
Enumeration class for defining the keypoint along a line segment.
|
static class |
LineSeg.Sign
Enumeration class for defining the orientations of a point relative to
the line segment.
|
static class |
LineSeg.TrigValues
Structure to hold onto trig values that represent an angle
|
| Constructor and Description |
|---|
LineSeg(LineSeg.KeyPoint start,
int fromX,
int fromY,
float slope,
long len,
int xdir)
Creates a segment using (fromX, fromY) as either the first point of the
segment (start == Origin) or the midpoint of the segment (start ==
Midpoint), and using slope as its new slope and len as the new length.
|
LineSeg(org.eclipse.draw2d.geometry.Point ptStart,
org.eclipse.draw2d.geometry.Point ptEnd)
Constructor
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
containsPoint(org.eclipse.draw2d.geometry.Point aPoint,
int tolerance)
Checks if this line segment contains the given point within a tolerance
value.
|
float |
distanceAlong(org.eclipse.draw2d.geometry.Point coord)
Finds the percentage distance along this line segement where the given
point resides.
|
long |
distanceToPoint(int xCoord,
int yCoord)
Finds the perpendicular distance from a point coordinates to this line
segment.
|
boolean |
equals(java.lang.Object seg) |
double[] |
getEquation()
Returns array with 3 numbers in it, which are the coefficients of the
generalized line equation of the line corresponding to this line segment
a*x+b*y=c is the equation => result[0]=a, result[1]=b, result[2]=c
|
org.eclipse.draw2d.geometry.Point |
getInfimum()
Get a
Point representing the lowest point value for this
line segment. |
static double[] |
getLineEquation(double x1,
double y1,
double x2,
double y2)
Returns the coefficients of the generalized equation of the line passing
through points (x1,y1) and (x2,y2) Generalized line equation: ax+by=c =>
a==result[0], b==result[1], c==result[2]
|
org.eclipse.draw2d.geometry.PointList |
getLineIntersectionsWithEllipse(org.eclipse.draw2d.geometry.Rectangle ellipseBounds)
Calculates intersection points of the line of the line segment and
ellipse
|
org.eclipse.draw2d.geometry.PointList |
getLineIntersectionsWithLineSegs(org.eclipse.draw2d.geometry.PointList points)
Calculates intersection points of the line that contains this line
segment with a list of other line segments.
|
org.eclipse.draw2d.geometry.PointList |
getLinesIntersections(LineSeg line)
Returns intersection points of two lines that contain this line segment
and the argumet line segment.
|
org.eclipse.draw2d.geometry.Point |
getOrigin()
Accesssor to retrieve the origin point of the line segement.
|
LineSeg |
getParallelLineSegThroughPoint(org.eclipse.draw2d.geometry.Point ptLoc)
Returns a new
LineSeg that is parallel to this by the given
distance. |
org.eclipse.draw2d.geometry.Point |
getSupremum()
Get points representing the highest point value for this line segment.
|
org.eclipse.draw2d.geometry.Point |
getTerminus()
Accesssor to retrieve the terminal point of the line segement.
|
LineSeg.TrigValues |
getTrigValues(org.eclipse.draw2d.geometry.Vector ptToVector)
Gets the trig values associated with the angle from this line segment to
the given vector.
|
int |
hashCode() |
org.eclipse.draw2d.geometry.Point |
intersect(LineSeg line,
int nTolerance)
Determines the intersect point between this line and the line passed in
as a parameter.
|
boolean |
isHorizontal()
Determines if this a horizontal segment
|
boolean |
isVertical()
Determines if this a vertical segment
|
double |
length()
Calculate the length of the line segment.
|
org.eclipse.draw2d.geometry.Point |
locatePoint(double pctDist,
long theHeight,
LineSeg.Sign asOriented)
Locates a point at a given height and distance along the line segment.
|
void |
performScale(double factor) |
void |
performTranslate(int dx,
int dy) |
org.eclipse.draw2d.geometry.Point |
perpIntersect(int startX,
int startY)
Calculates the perpendicular intersection point on the line segment from
the given point.
|
float |
perpSlope()
Calculates the perpendicular slope of this line segment.
|
boolean |
pointOn(long theDistance,
LineSeg.KeyPoint fromKeyPoint,
org.eclipse.draw2d.geometry.Point ptResult)
Gets the point on the line segment at the given distance away from the
key point.
|
LineSeg.Sign |
positionRelativeTo(org.eclipse.draw2d.geometry.Point rel)
Returns out a positive or negative value (Positive / Negative) depending
on the orientation of the given point to the line.
|
double |
projection(int xCoord,
int yCoord)
Calculates the projection of the given point onto the line segment.
|
void |
setOrigin(org.eclipse.draw2d.geometry.Point origin)
Sets the origin point of the line segment
|
void |
setTerminus(org.eclipse.draw2d.geometry.Point terminus)
Sets the terminating point of the line segment.
|
float |
slope()
Calculates the slope of this line segment (y=mx+b)
|
public LineSeg(LineSeg.KeyPoint start, int fromX, int fromY, float slope, long len, int xdir)
start - KeyPoint from which the other parameters are
relative tofromX - int x value of start KeyPointfromY - int y value of start KeyPointslope - float slope of the linelen - long length of the linexdir - directionpublic LineSeg(org.eclipse.draw2d.geometry.Point ptStart,
org.eclipse.draw2d.geometry.Point ptEnd)
ptStart - Point indicating the start of the line segmentptEnd - Point indicating the end of the line segmentpublic static double[] getLineEquation(double x1,
double y1,
double x2,
double y2)
x1 - - x coordinate of the 1st pointy1 - - y coordinate of the 1st pointx2 - - x coordinate of the 2nd pointy2 - - y coordinate of the 2nd pointpublic final boolean containsPoint(org.eclipse.draw2d.geometry.Point aPoint,
int tolerance)
aPoint - Point to test if contained in this line.tolerance - int tolerance value for detecting the intersection.boolean true if the given point lies on
this segment, false otherwise.public final float distanceAlong(org.eclipse.draw2d.geometry.Point coord)
coord - Point to determine how far along the line segment
it resides.float the distance along the line segment where the
ptCoord is in a percentage from.public final long distanceToPoint(int xCoord,
int yCoord)
xCoord - the x coordinate of the point.yCoord - the y coordinate of the point.long the distance from the line segment to the given
point.public boolean equals(java.lang.Object seg)
equals in class java.lang.Objectpublic double[] getEquation()
public final org.eclipse.draw2d.geometry.Point getInfimum()
Point representing the lowest point value for this
line segment.Point Representing the lowest point value.public org.eclipse.draw2d.geometry.PointList getLineIntersectionsWithEllipse(org.eclipse.draw2d.geometry.Rectangle ellipseBounds)
ellipseBounds - - width and height of the ellipsePointList containing all intersection pointspublic org.eclipse.draw2d.geometry.PointList getLineIntersectionsWithLineSegs(org.eclipse.draw2d.geometry.PointList points)
PolyLine, i.e form a closed polygon
figure, then the method will claculate intersections of a line and a
figurepoints - - list of points that form linesegments, i.e the
PolyLinepublic org.eclipse.draw2d.geometry.PointList getLinesIntersections(LineSeg line)
line - - the line segmentpublic org.eclipse.draw2d.geometry.Point getOrigin()
Point the origin of the line segment.public final LineSeg getParallelLineSegThroughPoint(org.eclipse.draw2d.geometry.Point ptLoc)
LineSeg that is parallel to this by the given
distance. Orientation is relative to the start and end. Negative implies
to the left and Position implies to the right.ptLoc - Point value to constrain the line to.LineSeg line that was calculated going through the
given pointpublic final org.eclipse.draw2d.geometry.Point getSupremum()
Point Representing the highest point value.public org.eclipse.draw2d.geometry.Point getTerminus()
Point the terminating point of the line segmentpublic LineSeg.TrigValues getTrigValues(org.eclipse.draw2d.geometry.Vector ptToVector)
ptToVector - Ray value to calculate trig values of.TrigValues object representing the trigonometry
values for the angle of the passed in Ray relative
to this or null if calculation is not possible,public int hashCode()
hashCode in class java.lang.Objectpublic org.eclipse.draw2d.geometry.Point intersect(LineSeg line, int nTolerance)
false.line - LineSeg to test the intersection against.nTolerance - int tolerance value for detecting the intersection.Point that represents the intersection with this
line, or null if the calculation is not possible.public final boolean isHorizontal()
boolean true if horizontal,
false otherwise.public final boolean isVertical()
boolean true if vertical,
false otherwise.public final double length()
double length of the line segment.public final org.eclipse.draw2d.geometry.Point locatePoint(double pctDist,
long theHeight,
LineSeg.Sign asOriented)
pctDist - double distance along the linetheHeight - long height above the lineasOriented - Sign indicating relative position of the point to
be locatedPoint value that was located on the line.public void performScale(double factor)
performScale in interface org.eclipse.draw2d.geometry.Translatablepublic void performTranslate(int dx,
int dy)
performTranslate in interface org.eclipse.draw2d.geometry.Translatablepublic final org.eclipse.draw2d.geometry.Point perpIntersect(int startX,
int startY)
startX - the x coordinate of the pointstartY - the y coordinate of the pointPoint value containment the perpendicular
intersection point.public final float perpSlope()
BIGSLOPE is returned if the calculated slope before
inverting it was zero.float the perpendicular slope value of the line
segment.public final boolean pointOn(long theDistance,
LineSeg.KeyPoint fromKeyPoint,
org.eclipse.draw2d.geometry.Point ptResult)
theDistance - long distance along the linefromKeyPoint - KeyPoint to calculate the distance fromptResult - Point where the resulting calculating value is
stored.boolean true if point can be
calculated, false otherwise.public final LineSeg.Sign positionRelativeTo(org.eclipse.draw2d.geometry.Point rel)
rel - Point to test the relative position against this
line.Sign value indicating the relative position of the
given point.public final double projection(int xCoord,
int yCoord)
xCoord - the x coordinate of the point.yCoord - the y coordinate of the point.double value of the calculated projection.public void setOrigin(org.eclipse.draw2d.geometry.Point origin)
origin - Point to set as originpublic void setTerminus(org.eclipse.draw2d.geometry.Point terminus)
terminus - Point to set as terminuspublic final float slope()
float the slope of this segment. If the slope is not
defined such as when the line segment is vertical, then the
constant BIGSLOPE is returned to avoid divide by
zero errors.