Class LineSegment


  • public class LineSegment
    extends Object
    Represent a line segment.
    • Constructor Detail

      • LineSegment

        public LineSegment​(Point p1,
                           Point p2)
        Create a line segment with two given endpoints.
        Parameters:
        p1 - the first endpoint
        p2 - the second endpoint
    • Method Detail

      • getEndPoint1

        public Point getEndPoint1()
        Get the first endpoint.
        Returns:
        the first endpoint
      • getEndPoint2

        public Point getEndPoint2()
        Get the second endpoint.
        Returns:
        the second endpoint
      • dimension

        public int dimension()
        Get the dimension of the coordinate space.
        Returns:
        the dimension of the coordinate space
      • length

        public double length()
        Get the length of the line segment.
        Returns:
        the line length
      • distance

        public double distance​(Point p)
        Calculate the shortest distance between a point and this line segment in Euclidean geometry. If the projection of the point on the line is outside of the segment, the distance between the point and the closest endpoint of the line segment is returned.
        Parameters:
        p - the point
        Returns:
        the distance
      • perpendicularDistance

        public double perpendicularDistance​(Point p)