LinearEquation
This interface represents a linear equation, which is a first-degree function where the highest power of X is 1. It extends Serializable and the Equation interface, providing methods to define and interact with straight lines in a 2D plane.
Key Concepts
- Infinite Line: Unlike
Line(which represents a segment),LinearEquationrepresents an infinite line. - Slope-Intercept Form: Many of its methods relate to the slope-intercept form of a linear equation (y = mx + b).
- Vertical Lines: Special handling is provided for vertical lines, which have an undefined slope.
Methods
getPoint()
Returns an arbitrary PointXY that lies on the line. This is particularly useful for vertical lines where a Y-intercept doesn't exist.
getSlope()
Returns the slope of the line as a double.
getIntercept()
Returns the Y-intercept of the equation. For vertical lines, this method might return a non-meaningful value or throw an exception depending on the implementation.
isVertical()
Checks if the line is vertical (i.e., has an undefined slope, or a slope of positive/negative infinity).
getVertical()
If the line is vertical, this method returns the X-coordinate of the line. If the line is not vertical, it returns 0.0.
getIntersection(LinearEquation equation)
Calculates and returns the PointXY where this linear equation intersects with another LinearEquation. This method considers the lines as infinite and does not take into account domain or range. If the lines are parallel and do not intersect, it returns null.
intersectsWith(LinearEquation equation)
Checks if this linear equation intersects with another LinearEquation. Generally returns true unless the lines are parallel.
getEquation(double x1, double y1, double x2, double y2)
Static method. Creates a new LinearEquation based on two given points (x1, y1) and (x2, y2).
getEquation(PointXY a, PointXY b)
Static method. Creates a new LinearEquation based on two given PointXY objects.