Package org.apache.sis.math
Class Line
Object
Line
- All Implemented Interfaces:
- Serializable,- Cloneable,- DoubleUnaryOperator
Equation of a line in a two dimensional space (x,y).
 A line can be expressed by the y = slope⋅x + y₀ equation
 where y₀ is the value of y at x = 0.
 
The equation parameters for a Line object can be set at construction time or using one
 of the setLine(…) methods. The y value can be computed for a given x
 value using the y(double) method. Method x(double) computes the converse and should
 work even if the line is vertical.
Comparison with Java2D geometries:
 At the difference of 
Line2D which is bounded by (x₁,y₁)
 and (x₂,y₂) points, Line objects extend toward infinity.- Since:
- 0.5
- See Also:
Defined in the sis-utility module
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptiondoubleapplyAsDouble(double x) Evaluates this equation for the given value.clone()Returns a clone of this line.booleanCompares this line with the specified object for equality.doublefit(double[] x, double[] y) Given a set of data points x[0 … n-1], y[0 … n-1], fits them to a straight line y = slope⋅x + y₀ in a least-squares senses.doublefit(Iterable<? extends DirectPosition> points) Given a sequence of points, fits them to a straight line y = slope⋅x + y₀ in a least-squares senses.doubleGiven a set of data points x[0 … n-1], y[0 … n-1], fits them to a straight line y = slope⋅x + y₀ in a least-squares senses.intReturns a hash code value for this line.voidsetEquation(double slope, double y0) Sets this line to the specified slope and offset.voidsetEquation(Number slope, Number y0) Sets this line from values of arbitraryNumbertype.voidsetFromPoints(double x1, double y1, double x2, double y2) Sets a line through the specified points.final doubleslope()Returns the slope.Returns a string representation of this line.voidtranslate(double dx, double dy) Translates the line.final doublex(double y) Computes x = f⁻¹(y).final doublex0()Returns the x value for y = 0.final doubley(double x) Computes y = f(x).final doubley0()Returns the y value for x = 0.Methods inherited from interface DoubleUnaryOperatorandThen, compose
- 
Constructor Details- 
Linepublic Line()Constructs an uninitialized line. All methods will returnDouble.NaN.
- 
Linepublic Line(double slope, double y0) Constructs a line with the specified slope and offset. The linear equation will be y = slope⋅x + y₀.- Parameters:
- slope- the slope.
- y0- the y value at x = 0.
- See Also:
 
 
- 
- 
Method Details- 
slopepublic final double slope()Returns the slope.
- 
x0public final double x0()Returns the x value for y = 0. Coordinate (x₀, 0) is the intersection point with the x axis.
- 
xpublic final double x(double y) Computes x = f⁻¹(y). If the line is horizontal, then this method returns an infinite value.- Parameters:
- y- the y value where to evaluate the inverse function.
- Returns:
- the x value for the given y value.
- See Also:
 
- 
y0public final double y0()Returns the y value for x = 0. Coordinate (0, y₀) is the intersection point with the y axis.
- 
ypublic final double y(double x) Computes y = f(x). If the line is vertical, then this method returns an infinite value.- Parameters:
- x- the x value where to evaluate the function.
- Returns:
- the y value for the given x value.
- See Also:
 
- 
applyAsDoublepublic double applyAsDouble(double x) Evaluates this equation for the given value. The default implementation delegates toy(x), but subclasses may override with different formulas. This method is provided for interoperability with libraries making use ofjava.util.function.- Specified by:
- applyAsDoublein interface- DoubleUnaryOperator
- Parameters:
- x- the value where to evaluate the function.
- Returns:
- the function value for the given operand.
- Since:
- 1.0
 
- 
translatepublic void translate(double dx, double dy) Translates the line. The slope stay unchanged.- Parameters:
- dx- the horizontal translation.
- dy- the vertical translation.
 
- 
setEquationpublic void setEquation(double slope, double y0) Sets this line to the specified slope and offset. The linear equation will be y = slope⋅x + y₀.- Parameters:
- slope- the slope.
- y0- the y value at x = 0.
- See Also:
 
- 
setEquationSets this line from values of arbitraryNumbertype. This method is invoked by algorithms that may produce other kind of numbers (for example with different precision) than the usualdoubleprimitive type. The default implementation delegates tosetEquation(double, double), but subclasses can override this method if they want to process other kind of numbers in a special way.- Parameters:
- slope- the slope.
- y0- the y value at x = 0.
- Since:
- 0.8
 
- 
setFromPointspublic void setFromPoints(double x1, double y1, double x2, double y2) Sets a line through the specified points. The line will continue toward infinity after the points.- Parameters:
- x1- coordinate x of the first point.
- y1- coordinate y of the first point.
- x2- coordinate x of the second point.
- y2- coordinate y of the second point.
 
- 
fitpublic double fit(double[] x, double[] y) Given a set of data points x[0 … n-1], y[0 … n-1], fits them to a straight line y = slope⋅x + y₀ in a least-squares senses. This method assumes that the x values are precise and all uncertainty is in y.The default implementation delegates to fit(Vector, Vector).- Parameters:
- x- vector of x values (independent variable).
- y- vector of y values (dependent variable).
- Returns:
- estimation of the correlation coefficient. The closer this coefficient is to +1 or -1, the better the fit.
- Throws:
- IllegalArgumentException- if x and y do not have the same length.
 
- 
fitGiven a set of data points x[0 … n-1], y[0 … n-1], fits them to a straight line y = slope⋅x + y₀ in a least-squares senses. This method assumes that the x values are precise and all uncertainty is in y.The default implementation delegates to fit(Iterable).- Parameters:
- x- vector of x values (independent variable).
- y- vector of y values (dependent variable).
- Returns:
- estimation of the correlation coefficient. The closer this coefficient is to +1 or -1, the better the fit.
- Throws:
- IllegalArgumentException- if x and y do not have the same length.
- Since:
- 0.8
 
- 
fitGiven a sequence of points, fits them to a straight line y = slope⋅x + y₀ in a least-squares senses. Points shall be two dimensional with coordinate values in the (x,y) order. This method assumes that the x values are precise and all uncertainty is in y.Double.NaNcoordinate values are ignored.- Parameters:
- points- the two-dimensional points.
- Returns:
- estimation of the correlation coefficient. The closer this coefficient is to +1 or -1, the better the fit.
- Throws:
- MismatchedDimensionException- if a point is not two-dimensional.
 
- 
cloneReturns a clone of this line.
- 
equalsCompares this line with the specified object for equality.
- 
hashCodepublic int hashCode()Returns a hash code value for this line.
- 
toStringReturns a string representation of this line. This method returns the linear equation in the form y = slope⋅x + y₀.
 
-