Class LineSeg

  • All Implemented Interfaces:
    java.io.Serializable, org.eclipse.draw2d.geometry.Translatable

    public class LineSeg
    extends java.lang.Object
    implements java.io.Serializable, org.eclipse.draw2d.geometry.Translatable
    See Also:
    Serialized Form
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class 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 Summary

      Constructors 
      Constructor Description
      LineSeg​(org.eclipse.draw2d.geometry.Point ptStart, org.eclipse.draw2d.geometry.Point ptEnd)
      Constructor
      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.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method 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)
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • 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
      • LineSeg

        public LineSeg​(org.eclipse.draw2d.geometry.Point ptStart,
                       org.eclipse.draw2d.geometry.Point ptEnd)
        Constructor
        Parameters:
        ptStart - Point indicating the start of the line segment
        ptEnd - Point indicating the end of the line segment
    • Method Detail

      • 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)
      • containsPoint

        public final boolean containsPoint​(org.eclipse.draw2d.geometry.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​(org.eclipse.draw2d.geometry.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.
      • equals

        public boolean equals​(java.lang.Object seg)
        Overrides:
        equals in class java.lang.Object
      • 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
      • getInfimum

        public final org.eclipse.draw2d.geometry.Point getInfimum()
        Get a Point representing the lowest point value for this line segment.
        Returns:
        Point Representing the lowest point value.
      • getLineIntersectionsWithEllipse

        public org.eclipse.draw2d.geometry.PointList getLineIntersectionsWithEllipse​(org.eclipse.draw2d.geometry.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 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. 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.
      • getLinesIntersections

        public org.eclipse.draw2d.geometry.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.
      • getOrigin

        public org.eclipse.draw2d.geometry.Point getOrigin()
        Accesssor to retrieve the origin point of the line segement.
        Returns:
        Point the origin of the line segment.
      • getParallelLineSegThroughPoint

        public final LineSeg getParallelLineSegThroughPoint​(org.eclipse.draw2d.geometry.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
      • getSupremum

        public final org.eclipse.draw2d.geometry.Point getSupremum()
        Get points representing the highest point value for this line segment.
        Returns:
        Point Representing the highest point value.
      • getTerminus

        public org.eclipse.draw2d.geometry.Point getTerminus()
        Accesssor to retrieve the terminal point of the line segement.
        Returns:
        Point the terminating point of the line segment
      • getTrigValues

        public 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.
        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,
      • hashCode

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

        public 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. 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.
      • 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.
      • length

        public final double length()
        Calculate the length of the line segment.
        Returns:
        the double length of the line segment.
      • locatePoint

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

        public void performScale​(double factor)
        Specified by:
        performScale in interface org.eclipse.draw2d.geometry.Translatable
      • performTranslate

        public void performTranslate​(int dx,
                                     int dy)
        Specified by:
        performTranslate in interface org.eclipse.draw2d.geometry.Translatable
      • perpIntersect

        public final org.eclipse.draw2d.geometry.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.
      • 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.
      • pointOn

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

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

        public void setOrigin​(org.eclipse.draw2d.geometry.Point origin)
        Sets the origin point of the line segment
        Parameters:
        origin - Point to set as origin
      • setTerminus

        public void setTerminus​(org.eclipse.draw2d.geometry.Point terminus)
        Sets the terminating point of the line segment.
        Parameters:
        terminus - Point to set as terminus
      • 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.