|
Runtime | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.eclipse.gmf.runtime.draw2d.ui.geometry.LineSeg
public class LineSeg
This is a geometric utility class that allows for manipulation of line segments. A line segment is defined as a set of two points where one point is designated as the origin and the other is the terminal.
| Nested Class Summary | |
|---|---|
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 Summary | |
|---|---|
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(Point ptStart,
Point ptEnd)
Constructor |
|
| Method Summary | |
|---|---|
boolean |
containsPoint(Point aPoint,
int tolerance)
Checks if this line segment contains the given point within a tolerance value. |
float |
distanceAlong(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 |
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] |
PointList |
getLineIntersectionsWithEllipse(Rectangle ellipseBounds)
Calculates intersection points of the line of the line segment and ellipse |
PointList |
getLineIntersectionsWithLineSegs(PointList points)
Calculates intersection points of the line that contains this line segment with a list of other line segments. |
PointList |
getLinesIntersections(LineSeg line)
Returns intersection points of two lines that contain this line segment and the argumet line segment. |
Point |
getOrigin()
Accesssor to retrieve the origin point of the line segement. |
LineSeg |
getParallelLineSegThroughPoint(Point ptLoc)
Returns a new LineSeg that is parallel to this by the given distance. |
Point |
getSupremum()
Get points representing the highest point value for this line segment. |
Point |
getTerminus()
Accesssor to retrieve the terminal point of the line segement. |
LineSeg.TrigValues |
getTrigValues(Ray ptToVector)
Gets the trig values associated with the angle from this line segment to the given vector. |
int |
hashCode()
|
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. |
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)
|
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,
Point ptResult)
Gets the point on the line segment at the given distance away from the key point. |
LineSeg.Sign |
positionRelativeTo(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(Point origin)
Sets the origin point of the line segment |
void |
setTerminus(Point terminus)
Sets the terminating point of the line segment. |
float |
slope()
Calculates the slope of this line segment (y=mx+b) |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public LineSeg(Point ptStart,
Point ptEnd)
ptStart - Point indicating the start of the line segmentptEnd - Point indicating the end of the line segment
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 - direction| Method Detail |
|---|
public boolean equals(java.lang.Object seg)
equals in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Objectpublic Point getOrigin()
Point the origin of the line segment.public Point getTerminus()
Point the terminating point of the line segmentpublic void setOrigin(Point origin)
origin - Point to set as originpublic void setTerminus(Point terminus)
terminus - Point to set as terminuspublic final Point getSupremum()
Point Representing the highest point value.public final Point getInfimum()
Point representing the lowest point value
for this line segment.
Point Representing the lowest point value.public final boolean isHorizontal()
boolean true if horizontal,
false otherwise.public final boolean isVertical()
boolean true if vertical,
false otherwise.public 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.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 double length()
double length of the line segment.
public 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 containsPoint(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(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 final Point perpIntersect(int startX,
int startY)
startX - the x coordinate of the pointstartY - the y coordinate of the point
Point value containment the perpendicular intersection 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 final LineSeg.Sign positionRelativeTo(Point rel)
rel - Point to test the relative position against this line.
Sign value indicating the relative position of the given point.
public final 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 located
Point value that was located on the line.
public final boolean pointOn(long theDistance,
LineSeg.KeyPoint fromKeyPoint,
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 LineSeg.TrigValues getTrigValues(Ray 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 final LineSeg getParallelLineSegThroughPoint(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 point
public 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 point
public double[] getEquation()
public PointList getLinesIntersections(LineSeg line)
line - - the line segment
public PointList getLineIntersectionsWithEllipse(Rectangle ellipseBounds)
ellipseBounds - - width and height of the ellipse
PointList containing all intersection pointspublic PointList getLineIntersectionsWithLineSegs(PointList points)
PolyLine, i.e form a closed polygon figure, then the method will
claculate intersections of a line and a figure
points - - list of points that form linesegments, i.e the PolyLine
public void performScale(double factor)
performScale in interface Translatable
public void performTranslate(int dx,
int dy)
performTranslate in interface Translatable
|
Runtime | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
Guidelines for using Eclipse APIs.
Copyright (c) IBM Corp., Borland Software Corp., and others 2005,2006. All rights reserved.