-
- All Implemented Interfaces:
-
it.unibo.alchemist.model.interfaces.geometry.euclidean2d.Line2D
public final class SlopeInterceptLine2D<P extends Vector2D<P>> implements Line2D<P>
A Line2D represented in the slope-intercept form: y = slope * x + yIntercept. Doubles are only compared with MathUtils.fuzzyEquals.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public classSlopeInterceptLine2D.Companion
-
Field Summary
Fields Modifier and Type Field Description private final BooleanisHorizontalprivate final BooleanisVerticalprivate final Doubleslopeprivate final DoubleyInterceptprivate final DoublexIntercept
-
Constructor Summary
Constructors Constructor Description SlopeInterceptLine2D(Double slope, Double yIntercept, Function2<Double, Double, P> createPoint)Creates a non-vertical line given its slope and yIntercept. SlopeInterceptLine2D(Double xIntercept, Function2<Double, Double, P> createPoint)Creates a vertical line given its xIntercept.
-
Method Summary
Modifier and Type Method Description BooleangetIsHorizontal()Indicates if the line is aligned to the x-axis. BooleangetIsVertical()Indicates if the line is aligned to the y-axis. DoublegetSlope()The slope of the line, if isVertical this is undefined (= Double.NaN). DoublegetYIntercept()The y-coordinate of the y-intercept (= the point where the line intersects the y-axis). DoublegetXIntercept()The x-coordinate of the x-intercept (= the point where the line intersects the x-axis). Booleancontains(P point)Checks if the point belongs to this line. final DoublefindY(Double x)Solves the line equation for the given x. PfindPoint(Double x)Finds the point belonging to the line with the given x-coordinate. BooleanisParallelTo(Line2D<P> other)Checks if two lines are parallel. final BooleancoincidesWith(Line2D<?> other)Checks if two lines coincide. Intersection2D<P>intersect(Line2D<P> other)Intersects two lines. Intersection2D<P>intersectCircle(P center, Double radius)Intersects a line and a circle. Booleanequals(Object other)Checks if other is a Line2D and if it coincidesWith this one. IntegerhashCode()Uses slope, yIntercept and xIntercept. -
-
Method Detail
-
getIsHorizontal
Boolean getIsHorizontal()
Indicates if the line is aligned to the x-axis.
-
getIsVertical
Boolean getIsVertical()
Indicates if the line is aligned to the y-axis.
-
getSlope
Double getSlope()
The slope of the line, if isVertical this is undefined (= Double.NaN).
-
getYIntercept
Double getYIntercept()
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.
-
getXIntercept
Double getXIntercept()
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.
-
findY
final Double findY(Double x)
Solves the line equation for the given x. Throws an UnsupportedOperationException if the line isVertical.
-
findPoint
P findPoint(Double x)
Finds the point belonging to the line with the given x-coordinate. Throws an UnsupportedOperationException if the line isVertical.
-
isParallelTo
Boolean isParallelTo(Line2D<P> other)
Checks if two lines are parallel.
-
coincidesWith
final Boolean coincidesWith(Line2D<?> other)
Checks if two lines coincide.
-
intersect
Intersection2D<P> intersect(Line2D<P> other)
Intersects two lines.
-
intersectCircle
Intersection2D<P> intersectCircle(P center, Double radius)
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.
-
hashCode
Integer hashCode()
Uses slope, yIntercept and xIntercept.
-
-
-
-