SlopeInterceptLine2D

A Line2D represented in the slope-intercept form: y = slope * x + yIntercept. Doubles are only compared with fuzzyEquals.

Constructors

Link copied to clipboard
constructor(slope: Double, yIntercept: Double, createPoint: (Double, Double) -> P)

Creates a non-vertical line given its slope and yIntercept.

constructor(xIntercept: Double, createPoint: (Double, Double) -> P)

Creates a vertical line given its xIntercept.

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
open override val isHorizontal: Boolean

Indicates if the line is aligned to the x-axis.

Link copied to clipboard
open override val isVertical: Boolean

Indicates if the line is aligned to the y-axis.

Link copied to clipboard
open override val slope: Double

The slope of the line, if isVertical this is undefined (= Double.NaN).

Link copied to clipboard
open override val xIntercept: Double

The x-coordinate of the x-intercept (= the point where the line intersects the x-axis). If isHorizontal there's no x-intercept and this is Double.NaN.

Link copied to clipboard
open override val yIntercept: Double

The y-coordinate of the y-intercept (= the point where the line intersects the y-axis). If isVertical there's no y-intercept and this is Double.NaN. The slope-intercept representation (y = mx + b) uses this intercept.

Functions

Link copied to clipboard
fun coincidesWith(other: Line2D<*>): Boolean

Checks if two lines coincide.

Link copied to clipboard
open override fun contains(point: P): Boolean

Checks if the point belongs to this line.

Link copied to clipboard
open operator override fun equals(other: Any?): Boolean

Checks if other is a Line2D and if it coincidesWith this one.

Link copied to clipboard
open override fun findPoint(x: Double): P

Finds the point belonging to the line with the given x-coordinate. Throws an UnsupportedOperationException if the line isVertical.

Link copied to clipboard

Solves the line equation for the given x. Throws an UnsupportedOperationException if the line isVertical.

Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard
open override fun intersect(other: Line2D<P>): Intersection2D<P>

Intersects two lines.

Link copied to clipboard
open override fun intersectCircle(center: P, radius: Double): Intersection2D<P>

Intersects a line and a circle. Radius must be positive. Intersection is performed by plugging the line equation in the circle equation and solving the resulting quadratic equation. Circle equation: (x - center.x)^2 + (y - center.y)^2 = r^2. Line equation: y = slope * x + yIntercept unless isVertical, x = xIntercept otherwise.

Link copied to clipboard
open override fun isParallelTo(other: Line2D<P>): Boolean

Checks if two lines are parallel.