Class Line2D
java.lang.Object
org.chsrobotics.lib.math.geometry.Line2D
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
ConstructorsConstructorDescriptionLine2D(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.Constructs a Line2D from polar form with a provided startpoint.Constructs a Line2D from Cartesian form with a provided startpoint. -
Method Summary
Modifier and TypeMethodDescriptiondoubleReturns the change in the X-axis from the start of the line to the end of the line.doubleReturns the change in the Y-axis from the start of the line to the end of the line.doubleReturns the angle of the line in radians from the startpoint.Returns the endpoint of the line.doubleReturns the absolute length of the line.Returns the startpoint of the line.booleanintersects(Line2D other) Returns whether a line intersects this line.booleanReturns whether a point lies upon the line.
-
Constructor Details
-
Line2D
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
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
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, returnsNaN.- 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
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
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
Returns the startpoint of the line.- Returns:
- A vector with endpoint representing the startpoint of this line.
-
getEndPoint
Returns the endpoint of the line.- Returns:
- A vector with endpoint representing the endpoint of this line.
-