Package common
Class Line
java.lang.Object
common.Line
Represents a line from point P1(x1, y1) to P2(x2, y2).
- Author:
- Krish Pillai
-
Constructor Summary
ConstructorsConstructorDescriptionLine(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.Copy constructor for the specified line.Constructs and initializes a line with the specified end locations P1, and P2, in the coordinate space. -
Method Summary
Modifier and TypeMethodDescriptiondoubleReturns angle in radians this line makes with the horizontal.booleanLines are equal if their end points are the same.getP1()Getter for the P1getP2()Getter for the P2intgetX1()Getter for the x coordinate of point P1intgetX2()Getter for the x coordinate of point P2intgetY1()Getter for the y coordinate of point P1intgetY2()Getter for the y coordinate of point P2doubleReturns the intercept of this line.doublelength()Returns the Euclidean distance between P1 and P2doubleslope()Returns the slope of the line.toString()
-
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 P1y1- the Y coordinate of Point P1x2- the X coordinate of Point P2y2- the Y coordinate of Point P2- Since:
- 1.0
- See Also:
-
Line
Copy constructor for the specified line.- Parameters:
line- The line to be duplicated- Since:
- 1.0
- See Also:
-
Line
Constructs and initializes a line with the specified end locations P1, and P2, in the coordinate space.- Parameters:
p1- the end-point P1p2- 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
Getter for the P1- Returns:
- p1 Point P1
-
getP2
Getter for the P2- Returns:
- p2 Point P2
-
toString
-
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
Lines are equal if their end points are the same. -
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
-