Class LineSegment


  • public class LineSegment
    extends Object
    This class defines a line segment. It consists of a start point and end point.
    • Constructor Detail

      • LineSegment

        public LineSegment​(Point start,
                           Point end)
        Constructs a new line segment.
        Parameters:
        start - the start point
        end - the end point
      • LineSegment

        public LineSegment​(double startX,
                           double startY,
                           double endX,
                           double endY)
        Constructs a new line segment.
        Parameters:
        startX - the X position of the start point
        startY - the Y position of the start point
        endX - the X position of the end point
        endY - the Y position of the end point
      • LineSegment

        public LineSegment​(Point start,
                           Vector vector)
        Constructs a new line segment.
        Parameters:
        start - the start point
        vector - the vector from the start point to the end point
    • Method Detail

      • getStart

        public Point getStart()
        Returns the start point.
        Returns:
        the start point
      • setStart

        public void setStart​(Point start)
        Sets the start point.
        Parameters:
        start - the start point
      • getEnd

        public Point getEnd()
        Returns the end point.
        Returns:
        the end point
      • setEnd

        public void setEnd​(Point end)
        Sets the end point.
        Parameters:
        end - the end point
      • toVector

        public Vector toVector()
        Returns the vector from the start point to the end point.
        Returns:
        the vector from the start point to the end point
      • getLength

        public double getLength()
        Returns the length of this line segment.
        Returns:
        the length of this line segment
      • rotate

        public void rotate​(double angle)
        Rotates this line segment by the specified number of degrees around the start point.
        Parameters:
        angle - the angle in degrees
      • offset

        public void offset​(double dx,
                           double dy)
        Moves this line segment by the specified offset.
        Parameters:
        dx - the offset along the X axis
        dy - the offset along the Y axis