Class Segment

  • Direct Known Subclasses:
    PolygonsSet.ConnectableSegment

    public class Segment
    extends java.lang.Object
    Simple container for a two-points segment.
    Since:
    3.0
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private Vector2D end
      End point of the segment.
      private Line line
      Line containing the segment.
      private Vector2D start
      Start point of the segment.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      double distance​(Vector2D p)
      Calculates the shortest distance from a point to this line segment.
      Vector2D getEnd()
      Get the end point of the segment.
      Line getLine()
      Get the line containing the segment.
      Vector2D getStart()
      Get the start point of the segment.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • start

        private final Vector2D start
        Start point of the segment.
      • end

        private final Vector2D end
        End point of the segment.
      • line

        private final Line line
        Line containing the segment.
    • Constructor Detail

      • Segment

        public Segment​(Vector2D start,
                       Vector2D end,
                       Line line)
        Build a segment.
        Parameters:
        start - start point of the segment
        end - end point of the segment
        line - line containing the segment
    • Method Detail

      • getStart

        public Vector2D getStart()
        Get the start point of the segment.
        Returns:
        start point of the segment
      • getEnd

        public Vector2D getEnd()
        Get the end point of the segment.
        Returns:
        end point of the segment
      • getLine

        public Line getLine()
        Get the line containing the segment.
        Returns:
        line containing the segment
      • distance

        public double distance​(Vector2D p)
        Calculates the shortest distance from a point to this line segment.

        If the perpendicular extension from the point to the line does not cross in the bounds of the line segment, the shortest distance to the two end points will be returned.

        Algorithm adapted from: Thread @ Codeguru
        Parameters:
        p - to check
        Returns:
        distance between the instance and the point
        Since:
        3.1