Package math

Class Line

java.lang.Object
math.Line

public class Line
extends java.lang.Object
Author:
GBEMIRO
  • Constructor Summary

    Constructors 
    Constructor Description
    Line()
    Creates a straight line parallel to the x axis
    Line​(double m, double c)
    Creates a new Line object give the gradient and the y intercept
    Line​(double x1, double y1, double x2, double y2)
    Creates a line between points joining: the points x1,y1 and x2,y2
    Line​(double m, Point p)
    Creates a new Line object give the gradient and a point on the line.
    Line​(Point p1, Point p2)
    Creates a line between points joining: the points p1 and p2
  • Method Summary

    Modifier and Type Method Description
    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.
    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 distance​(Point p1, Point p2)
    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 draw​(java.lang.Object g, double x1, double x2)
    Draws this Line object for the interval between x1 and x2.
    double getC()  
    double getM()  
    double getX​(double y)  
    double getY​(double x)  
    Point intersectionWithLine​(Line line)  
    boolean intersectsLine​(Line line)  
    boolean isParallelTo​(Line line)
    Checks if this Line object is parallel to another.
    static void main​(java.lang.String[] args)  
    boolean passesThroughPoint​(Point p1)  
    void setC​(double c)  
    void setM​(double m)  
    java.lang.String toString()  

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • 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 object
      c - the y intercept of the Line object
    • Line

      public Line​(double m, Point p)
      Creates a new Line object give the gradient and a point on the line.
      Parameters:
      m - the gradient of the Line object
      p - 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 point
      y1 - the y coordinate of the first point
      x2 - the x coordinate of the second point
      y2 - the y coordinate of the second point
    • Line

      public Line​(Point p1, Point p2)
      Creates a line between points joining: the points p1 and p2
      Parameters:
      p1 - the first point
      p2 - the second point
  • 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

      public double distance​(Point p1, Point p2)
      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 consider
      p2 - the second Point object to consider
      Returns:
      the distance along this Line object between the 2 given Point objects lying on it
    • distanceSquared

      public 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;
      Parameters:
      p1 - the first Point object to consider
      p2 - the second Point object to consider
      Returns:
      the distance along this Line object between the 2 given Point objects lying on it
    • intersectsLine

      public boolean intersectsLine​(Line line)
      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

      public boolean isParallelTo​(Line line)
      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

      public boolean passesThroughPoint​(Point p1)
      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

      public Point intersectionWithLine​(Line line)
      Parameters:
      line - the Line object whose point of intersection with this Line object is required
      Returns:
      the point of intersection of both Line objects
    • draw

      public void draw​(java.lang.Object g, double x1, double x2)
      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 start
      x2 - 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 compare
      val2 - 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 compare
      val2 - the second value to compare
      minDeviation - the minimum difference they must have to be acceptably equal.
      Returns:
      true if the values deviate by 1.0E-14 or lesser.
    • toString

      public java.lang.String toString()
      Overrides:
      toString in class java.lang.Object
    • main

      public static void main​(java.lang.String[] args)