Class Line
java.lang.Object
math.Line
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionLine()
Creates a straight line parallel to the x axisLine
(double m, double c) Creates a new Line object give the gradient and the y interceptLine
(double x1, double y1, double x2, double y2) Creates a line between points joining: the points x1,y1 and x2,y2Creates a new Line object give the gradient and a point on the line.Creates a line between points joining: the points p1 and p2 -
Method Summary
Modifier and TypeMethodDescriptionboolean
approxEquals
(double val1, double val2) Compares two numbers to see if they are close enough to be almost the same It checks if the values deviate by 1.0E-14 or lesser.boolean
approxEquals
(double val1, double val2, double minDeviation) Compares two numbers to see if they are close enough to be almost the same It checks if the values deviate by 1.0E-14 or lesser.double
Finds the distance between 2 Point objects lying on this Line object They must lie on this Line object, else the method will return 0;double
distanceSquared
(Point p1, Point p2) Finds the square of the distance between 2 Point objects lying on this Line object They must lie on this Line object, else the method will return 0;void
Draws this Line object for the interval between x1 and x2.double
getC()
double
getM()
double
getX
(double y) double
getY
(double x) intersectionWithLine
(Line line) boolean
intersectsLine
(Line line) boolean
isParallelTo
(Line line) Checks if this Line object is parallel to another.static void
boolean
void
setC
(double c) void
setM
(double m) toString()
-
Field Details
-
m
private double m -
c
private double c
-
-
Constructor Details
-
Line
public Line()Creates a straight line parallel to the x axis -
Line
public Line(double m, double c) Creates a new Line object give the gradient and the y intercept- Parameters:
m
- the gradient of the Line objectc
- the y intercept of the Line object
-
Line
Creates a new Line object give the gradient and a point on the line.- Parameters:
m
- the gradient of the Line objectp
- a Point object that lies on the Line object.
-
Line
public Line(double x1, double y1, double x2, double y2) Creates a line between points joining: the points x1,y1 and x2,y2- Parameters:
x1
- the x coordinate of the first pointy1
- the y coordinate of the first pointx2
- the x coordinate of the second pointy2
- the y coordinate of the second point
-
Line
-
-
Method Details
-
setM
public void setM(double m) - Parameters:
m
- sets the gradient of this Line.
-
getM
public double getM()- Returns:
- the gradient of this Line.
-
setC
public void setC(double c) - Parameters:
c
- sets the intercept of this Line.
-
getC
public double getC()- Returns:
- the intercept of this Line.
-
getX
public double getX(double y) - Parameters:
y
- the y coordinate of a given point on a Line object.- Returns:
- the x coordinate of that point.
-
getY
public double getY(double x) - Parameters:
x
- the x coordinate of a given point on a Line object.- Returns:
- the y coordinate of that point.
-
distance
Finds the distance between 2 Point objects lying on this Line object They must lie on this Line object, else the method will return 0;- Parameters:
p1
- the first Point object to considerp2
- the second Point object to consider- Returns:
- the distance along this Line object between the 2 given Point objects lying on it
-
distanceSquared
Finds the square of the distance between 2 Point objects lying on this Line object They must lie on this Line object, else the method will return 0;- Parameters:
p1
- the first Point object to considerp2
- the second Point object to consider- Returns:
- the distance along this Line object between the 2 given Point objects lying on it
-
intersectsLine
- Parameters:
line
- the Line object to be checked if or not it intersects with this one.- Returns:
- true if the 2 Line objects intersect.
-
isParallelTo
Checks if this Line object is parallel to another.- Parameters:
line
- the Line object to be checked against this one for parallelism- Returns:
- true if it is parallel to the other Line object
-
passesThroughPoint
- Parameters:
p1
- the Point object that we wish to check if or not it lies on this Line object.- Returns:
- true if it lies on this Line object
-
intersectionWithLine
-
draw
Draws this Line object for the interval between x1 and x2.- Parameters:
g
- The Graphics object used to draw this Line object.x1
- The x coordinate of the first point on this Line object where drawing is to startx2
- The x coordinate of the second point on this Line object where drawing is to start
-
approxEquals
public boolean approxEquals(double val1, double val2) Compares two numbers to see if they are close enough to be almost the same It checks if the values deviate by 1.0E-14 or lesser.- Parameters:
val1
- the first value to compareval2
- the second value to compare- Returns:
- true if the values deviate by 1.0E-14 or lesser.
-
approxEquals
public boolean approxEquals(double val1, double val2, double minDeviation) Compares two numbers to see if they are close enough to be almost the same It checks if the values deviate by 1.0E-14 or lesser.- Parameters:
val1
- the first value to compareval2
- the second value to compareminDeviation
- the minimum difference they must have to be acceptably equal.- Returns:
- true if the values deviate by 1.0E-14 or lesser.
-
toString
-
main
-