Class Line


  • public class Line
    extends Object
    This class defines a line. It consists of an origin and a vector. The origin should be considered as an anchor, not as a starting point. The line does not have a start or end.
    • Constructor Detail

      • Line

        public Line​(Point origin,
                    Vector vector)
        Constructs a new line.
        Parameters:
        origin - the origin
        vector - the vector
    • Method Detail

      • getOrigin

        public Point getOrigin()
        Returns the origin.
        Returns:
        the origin
      • setOrigin

        public void setOrigin​(Point origin)
        Sets the origin.
        Parameters:
        origin - the origin
      • getVector

        public Vector getVector()
        Returns the vector.
        Returns:
        the vector
      • setVector

        public void setVector​(Vector vector)
        Sets the vector.
        Parameters:
        vector - the vector
      • isParallel

        public boolean isParallel​(Line other)
        Returns whether another line is parallel to this line. This is also true if the other line moves in the opposite direction. The other line may or may not overlap this line.
        Parameters:
        other - the other line
        Returns:
        true if the other line is parallel to this line, false otherwise
      • containsPoint

        public boolean containsPoint​(Point point)
        Returns whether this line contains the specified point.
        Parameters:
        point - the point
        Returns:
        true if this line contains the specified point, false otherwise
      • findIntersection

        public Point findIntersection​(Line other)
        Tries to find an intersection between this line and another line. If the lines overlap each other, this method returns the origin of this line. If they are parallel, this method returns null. Otherwise this method returns the intersection.
        Parameters:
        other - the other line
        Returns:
        the intersection or null
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object