Package common

Class Line

java.lang.Object
common.Line

public class Line extends Object
Represents a line from point P1(x1, y1) to P2(x2, y2).
Author:
Krish Pillai
  • Constructor Summary

    Constructors
    Constructor
    Description
    Line(int x1, int y1, int x2, int y2)
    Constructs and initializes a line with the specified end locations P1, and P2, in the coordinate space.
    Line(Line line)
    Copy constructor for the specified line.
    Line(Point p1, Point p2)
    Constructs and initializes a line with the specified end locations P1, and P2, in the coordinate space.
  • Method Summary

    Modifier and Type
    Method
    Description
    double
    Returns angle in radians this line makes with the horizontal.
    boolean
    Lines are equal if their end points are the same.
    Getter for the P1
    Getter for the P2
    int
    Getter for the x coordinate of point P1
    int
    Getter for the x coordinate of point P2
    int
    Getter for the y coordinate of point P1
    int
    Getter for the y coordinate of point P2
    double
    Returns the intercept of this line.
    double
    Returns the Euclidean distance between P1 and P2
    double
    Returns the slope of the line.
     

    Methods inherited from class java.lang.Object

    getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Line

      public Line(int x1, int y1, int x2, int y2)
      Constructs and initializes a line with the specified end locations P1, and P2, in the coordinate space.
      Parameters:
      x1 - the X coordinate of Point P1
      y1 - the Y coordinate of Point P1
      x2 - the X coordinate of Point P2
      y2 - the Y coordinate of Point P2
      Since:
      1.0
      See Also:
    • Line

      public Line(Line line)
      Copy constructor for the specified line.
      Parameters:
      line - The line to be duplicated
      Since:
      1.0
      See Also:
    • Line

      public Line(Point p1, Point p2)
      Constructs and initializes a line with the specified end locations P1, and P2, in the coordinate space.
      Parameters:
      p1 - the end-point P1
      p2 - the end-point P2
      Since:
      1.0
      See Also:
  • Method Details

    • getX1

      public int getX1()
      Getter for the x coordinate of point P1
      Returns:
      x coordinate of P1
    • getY1

      public int getY1()
      Getter for the y coordinate of point P1
      Returns:
      y coordinate of P1
    • getX2

      public int getX2()
      Getter for the x coordinate of point P2
      Returns:
      x coordinate of P2
    • getY2

      public int getY2()
      Getter for the y coordinate of point P2
      Returns:
      y coordinate of P2
    • getP1

      public Point getP1()
      Getter for the P1
      Returns:
      p1 Point P1
    • getP2

      public Point getP2()
      Getter for the P2
      Returns:
      p2 Point P2
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • slope

      public double slope()
      Returns the slope of the line. The value of m when represented as y = mx + c, the general form.
      Returns:
      slope Change in y over change in x
    • length

      public double length()
      Returns the Euclidean distance between P1 and P2
      Returns:
      the distance between points
    • equals

      public boolean equals(Object obj)
      Lines are equal if their end points are the same.
      Overrides:
      equals in class Object
      Returns:
      true or false
    • intercept

      public double intercept()
      Returns the intercept of this line. The value of c when represented as y = mx + c, the general form.
      Returns:
      y-intercept
      Since:
      1.0
    • angleWithHorizontal

      public double angleWithHorizontal()
      Returns angle in radians this line makes with the horizontal. Zero degrees is the horizontal. The value of c when represented as y = mx + c, the general form. Value ranges from 0 to 180 (cw) and 0 to -180 (ccw).
      Returns:
      angle in radians
      Since:
      1.0