Class Line2D

java.lang.Object
org.chsrobotics.lib.math.geometry.Line2D

public class Line2D extends Object
Class representing a line in 2-dimensional space, in the form of a vector. This differs from Vector2D in that it does not necessarily have a startpoint at the origin, and that it contains methods to calculate whether points lie on it or if other lines intersect it.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Line2D(double magnitude, double directionRadians)
    Constructs a Line2D from polar form with a startpoint at the origin.
    Constructs a Line2D from Cartesian form using the origin as the startpoint.
    Line2D(Vector2D origin, double magnitude, double directionRadians)
    Constructs a Line2D from polar form with a provided startpoint.
    Line2D(Vector2D origin, Vector2D end)
    Constructs a Line2D from Cartesian form with a provided startpoint.
  • Method Summary

    Modifier and Type
    Method
    Description
    double
    Returns the change in the X-axis from the start of the line to the end of the line.
    double
    Returns the change in the Y-axis from the start of the line to the end of the line.
    double
    Returns the angle of the line in radians from the startpoint.
    Returns the endpoint of the line.
    double
    Returns the absolute length of the line.
    Returns the startpoint of the line.
    boolean
    Returns whether a line intersects this line.
    boolean
    Returns whether a point lies upon the line.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Line2D

      public Line2D(Vector2D origin, double magnitude, double directionRadians)
      Constructs a Line2D from polar form with a provided startpoint.
      Parameters:
      origin - A vector with endpoint representing the startpoint of the line.
      magnitude - The absolute length of the line.
      directionRadians - The angle of the line in radians (from start to endpoint).
    • Line2D

      public Line2D(double magnitude, double directionRadians)
      Constructs a Line2D from polar form with a startpoint at the origin.
      Parameters:
      magnitude - The absolute length of the line.
      directionRadians - The angle of the line in radians (from origin to endpoint).
    • Line2D

      public Line2D(Vector2D origin, Vector2D end)
      Constructs a Line2D from Cartesian form with a provided startpoint.
      Parameters:
      origin - A vector with endpoint representing the startpoint of the line.
      end - A vector with endpoint representing the endpoint of the line.
    • Line2D

      public Line2D(Vector2D end)
      Constructs a Line2D from Cartesian form using the origin as the startpoint.
      Parameters:
      end - A vector with endpoint representing the endpoint of the line.
  • Method Details

    • getDirectionRadians

      public double getDirectionRadians()
      Returns the angle of the line in radians from the startpoint. If the line is vertical, returns NaN.
      Returns:
      The angle of the vector from startpoint to endpoint.
    • getMagnitude

      public double getMagnitude()
      Returns the absolute length of the line.
      Returns:
      The absolute distance between the startpoint and endpoint.
    • getDeltaX

      public double getDeltaX()
      Returns the change in the X-axis from the start of the line to the end of the line.
      Returns:
      The difference in the X of the endpoint and the startpoint.
    • getDeltaY

      public double getDeltaY()
      Returns the change in the Y-axis from the start of the line to the end of the line.
      Returns:
      The difference in the Y of the endpoint and the startpoint.
    • pointOn

      public boolean pointOn(Vector2D point)
      Returns whether a point lies upon the line.
      Parameters:
      point - A vector with endpoint representing the point.
      Returns:
      Whether the point lies on the line within an epsilon.
    • intersects

      public boolean intersects(Line2D other)
      Returns whether a line intersects this line.
      Parameters:
      other - The other line.
      Returns:
      Whether the two lines intersect (colinearity over the same space counts).
    • getStartPoint

      public Vector2D getStartPoint()
      Returns the startpoint of the line.
      Returns:
      A vector with endpoint representing the startpoint of this line.
    • getEndPoint

      public Vector2D getEndPoint()
      Returns the endpoint of the line.
      Returns:
      A vector with endpoint representing the endpoint of this line.