File-By-File
SlopeIntercept

SlopeIntercept

The most simple implementation of the LinearEquation interface, the SlopeIntercept form is a classic representation of a linear equation: y = mx + b.

Methods

SlopeIntercept(double slope, double intercept)

Constructs a new SlopeIntercept instance with the given slope (m) and intercept (b). Throws an IllegalArgumentException if the slope or intercept are not finite numbers.

newVertical(double x)

Static factory method. Creates a new vertical linear equation. A vertical line has an undefined slope, so this constructor handles that special case by storing the X-intercept (x) and setting an internal flag isVertical to true.

getY(double x)

Returns the Y-value of the line at a specific X-value. For non-vertical lines, this is calculated using y = mx + b. For vertical lines, this method will return the Y-value on the vertical line at the given X, if the X matches the vertical line's X. Otherwise, its behavior is undefined or may throw an error depending on context.

getPoint(double x)

Returns a PointXY object representing a point on the line at the given X-value.

getPoint()

Returns a PointXY representing the Y-intercept of the line (the point where X is 0). For vertical lines, this returns a point on the vertical line at X=0.

getSlope()

Returns the slope of the line.

getIntercept()

Returns the Y-intercept of the line.

isVertical()

Returns true if the line is vertical (has an infinite slope), false otherwise.

getVertical()

If the line is vertical, returns the X-coordinate of the vertical line. Otherwise, returns 0.0.

getIntersection(LinearEquation equation)

Calculates and returns the PointXY where this linear equation intersects with another LinearEquation. It handles cases for both vertical and non-vertical lines. If the lines are parallel and do not intersect, it returns null.

intersectsWith(LinearEquation equation)

Checks if this linear equation intersects with another LinearEquation. This method generally returns true unless the equations are parallel.