Class Line

java.lang.Object
com.github.gbenroscience.math.geom.Line
Direct Known Subclasses:
Line3D

public class Line extends Object
Author:
GBEMIRO
  • 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 given 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.
    • isVertical

      public boolean isVertical()
      Returns:
      true if this Line object is a vertical one.
    • getxValue

      public double getxValue()
      This method tells the constant value that a vertical line, one whose equation is of the form x = constant has.
      Returns:
      the constant value that x has along this line, if and only if this line is vertical.
    • 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
    • getParallelLineAtDistance

      public Line getParallelLineAtDistance(double d)
      Parameters:
      d - The distance.
      Returns:
      the equation of a parallel line at a given perpendicular distance from this Line object.
    • getParallelLineAtDistance

      public Line getParallelLineAtDistance(int horDisp, int verDisp)
      Parameters:
      horDisp - The horizontal displacement of the new line from this line.
      verDisp - The vertical displacement of the new line from this line.
      Returns:
      the equation of a parallel line at a given horizontal displacement and a given vertical displacement from this object.
    • 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(Graphics 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 static 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 static 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.
    • rotate

      public void rotate(double ang, Point p)
      Parameters:
      ang - The angle of rotation in rads.
      p - The point about which to rotate this Line object,
    • rotateLine

      public Line rotateLine(double ang, Point p)
      Parameters:
      ang - The angle of rotation in rads.
      p - The point about which to rotate this Line object,
      Returns:
      a new Line object after rotating it through theta rads about point, p.
    • polygonIntersects

      public static boolean polygonIntersects(Polygon p1, Polygon p2)
      Parameters:
      p1 - The first polygon.
      p2 - The second polygon.
      Returns:
      true if the 2 polygons intersect.
    • polygonIntersectsNew

      public static boolean polygonIntersectsNew(Polygon p1, Polygon p2)
    • polygonIntersects

      public static boolean polygonIntersects(Polygon polygon, Rectangle rect)
      Parameters:
      polygon -
      rect -
      Returns:
      true if the polygon and the rectangle intersect.
    • polygonArea

      public static double polygonArea(Polygon p)
      Parameters:
      p - A polygon whose area is required.
    • convertRectangleToPolygon

      public static Polygon convertRectangleToPolygon(Rectangle rectangle)
      Parameters:
      rectangle -
      Returns:
      a java.awt.Polygon object that has the same properties as the rectangle
    • toString

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

      public static void main(String[] args)