Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

Runtime

org.eclipse.gmf.runtime.draw2d.ui.geometry
Class LineSeg

java.lang.Object
  extended by 
org.eclipse.gmf.runtime.draw2d.ui.geometry.LineSeg
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, Translatable

public class LineSeg
extends java.lang.Object
implements java.lang.Cloneable, java.io.Serializable, Translatable

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.

See Also:
Serialized Form

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

LineSeg

public LineSeg(
Point ptStart,
               
Point ptEnd)
Constructor

Parameters:
ptStart - Point indicating the start of the line segment
ptEnd - Point indicating the end of the line segment

LineSeg

public 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. xdir indicates which direction the segment should go in the x-axis.

Parameters:
start - KeyPoint from which the other parameters are relative to
fromX - int x value of start KeyPoint
fromY - int y value of start KeyPoint
slope - float slope of the line
len - long length of the line
xdir - direction
Method Detail

equals

public boolean equals(java.lang.Object seg)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

getOrigin

public 
Point getOrigin()
Accesssor to retrieve the origin point of the line segement.

Returns:
Point the origin of the line segment.

getTerminus

public 
Point getTerminus()
Accesssor to retrieve the terminal point of the line segement.

Returns:
Point the terminating point of the line segment

setOrigin

public void setOrigin(
Point origin)
Sets the origin point of the line segment

Parameters:
origin - Point to set as origin

setTerminus

public void setTerminus(
Point terminus)
Sets the terminating point of the line segment.

Parameters:
terminus - Point to set as terminus

getSupremum

public final 
Point getSupremum()
Get points representing the highest point value for this line segment.

Returns:
Point Representing the highest point value.

getInfimum

public final 
Point getInfimum()
Get a Point representing the lowest point value for this line segment.

Returns:
Point Representing the lowest point value.

isHorizontal

public final boolean isHorizontal()
Determines if this a horizontal segment

Returns:
boolean true if horizontal, false otherwise.

isVertical

public final boolean isVertical()
Determines if this a vertical segment

Returns:
boolean true if vertical, false otherwise.

slope

public final float slope()
Calculates the slope of this line segment (y=mx+b)

Returns:
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.

perpSlope

public final float perpSlope()
Calculates the perpendicular slope of this line segment. This calculates the slope and then inverts it. Again, to avoid divide by zero errors, the constant BIGSLOPE is returned if the calculated slope before inverting it was zero.

Returns:
float the perpendicular slope value of the line segment.

length

public final double length()
Calculate the length of the line segment.

Returns:
the double length of the line segment.

intersect

public 
Point intersect(
LineSeg line,
                       int nTolerance)
Determines the intersect point between this line and the line passed in as a parameter. If they intersect, then true is returned and the point reference passed in will be set to the intersect point. If they don't intersect, then the method returns false.

Parameters:
line - LineSeg to test the intersection against.
nTolerance - int tolerance value for detecting the intersection.
Returns:
Point that represents the intersection with this line, or null if the calculation is not possible.

containsPoint

public final boolean containsPoint(
Point aPoint,
                                   int tolerance)
Checks if this line segment contains the given point within a tolerance value.

Parameters:
aPoint - Point to test if contained in this line.
tolerance - int tolerance value for detecting the intersection.
Returns:
boolean true if the given point lies on this segment, false otherwise.

distanceAlong

public final float distanceAlong(
Point coord)
Finds the percentage distance along this line segement where the given point resides.

Parameters:
coord - Point to determine how far along the line segment it resides.
Returns:
float the distance along the line segment where the ptCoord is in a percentage from.

distanceToPoint

public final long distanceToPoint(int xCoord,
                                  int yCoord)
Finds the perpendicular distance from a point coordinates to this line segment. If point is "inside" line segment, then use distance from point to the line, otherwise use distance to nearest endpoint of segment

Parameters:
xCoord - the x coordinate of the point.
yCoord - the y coordinate of the point.
Returns:
long the distance from the line segment to the given point.

perpIntersect

public final 
Point perpIntersect(int startX,
                                 int startY)
Calculates the perpendicular intersection point on the line segment from the given point.

Parameters:
startX - the x coordinate of the point
startY - the y coordinate of the point
Returns:
Point value containment the perpendicular intersection point.

projection

public final double projection(int xCoord,
                               int yCoord)
Calculates the projection of the given point onto the line segment.

Parameters:
xCoord - the x coordinate of the point.
yCoord - the y coordinate of the point.
Returns:
double value of the calculated projection.

positionRelativeTo

public final 
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. Point on this side: Positive. P1------------------------------> this segment Point on this side: Negative.

Parameters:
rel - Point to test the relative position against this line.
Returns:
Sign value indicating the relative position of the given point.

locatePoint

public final 
Point locatePoint(double pctDist,
                               long theHeight,
                               
LineSeg.Sign asOriented)
Locates a point at a given height and distance along the line segment. B (the point we are looking for) + | dist |h this segment P1-----------+-------------------> A get point A (on picture above)

Parameters:
pctDist - double distance along the line
theHeight - long height above the line
asOriented - Sign indicating relative position of the point to be located
Returns:
Point value that was located on the line.

pointOn

public final 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.

Parameters:
theDistance - long distance along the line
fromKeyPoint - KeyPoint to calculate the distance from
ptResult - Point where the resulting calculating value is stored.
Returns:
boolean true if point can be calculated, false otherwise.

getTrigValues

public 
LineSeg.TrigValues getTrigValues(
Ray ptToVector)
Gets the trig values associated with the angle from this line segment to the given vector.

Parameters:
ptToVector - Ray value to calculate trig values of.
Returns:
TrigValues object representing the trigonometry values for the angle of the passed in Ray relative to this or null if calculation is not possible,

getParallelLineSegThroughPoint

public final 
LineSeg getParallelLineSegThroughPoint(
Point ptLoc)
Returns a new 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.

Parameters:
ptLoc - Point value to constrain the line to.
Returns:
LineSeg line that was calculated going through the given point

getLineEquation

public 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]

Parameters:
x1 - - x coordinate of the 1st point
y1 - - y coordinate of the 1st point
x2 - - x coordinate of the 2nd point
y2 - - y coordinate of the 2nd point
Returns:
the coefficients of the generalized equation of the line passing through points (x1,y1) and (x2,y2)

getEquation

public 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

Returns:
an array with 3 numbers in it, which are the coefficients of the generalized line equation

getLinesIntersections

public 
PointList getLinesIntersections(
LineSeg line)
Returns intersection points of two lines that contain this line segment and the argumet line segment. The list of intersection points may contain at most two points and will contain 2 points if and only if the lines are equal. The 2 points will be the end points of the parameter line segment

Parameters:
line - - the line segment
Returns:
intersection points of two lines that contain this line segment and the argumet line segment.

getLineIntersectionsWithEllipse

public 
PointList getLineIntersectionsWithEllipse(
Rectangle ellipseBounds)
Calculates intersection points of the line of the line segment and ellipse

Parameters:
ellipseBounds - - width and height of the ellipse
Returns:
- PointList containing all intersection points

getLineIntersectionsWithLineSegs

public 
PointList getLineIntersectionsWithLineSegs(
PointList points)
Calculates intersection points of the line that contains this line segment with a list of other line segments. If the list of points (line segments) form a closed PolyLine, i.e form a closed polygon figure, then the method will claculate intersections of a line and a figure

Parameters:
points - - list of points that form linesegments, i.e the PolyLine
Returns:
the intersection points of the line that contains this line segment with a list of other line segments.

performScale

public void performScale(double factor)
Specified by:
performScale in interface Translatable

performTranslate

public void performTranslate(int dx,
                             int dy)
Specified by:
performTranslate in interface Translatable

Runtime

Guidelines for using Eclipse APIs.

Copyright (c) IBM Corp., Borland Software Corp., and others 2005,2006. All rights reserved.


 
 
  Published under the terms of the Eclipse Public License Version 1.0 ("EPL") Design by Interspire