public class Line extends Object implements Cloneable, Serializable
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.
Line2D
which is bounded by (x₁,y₁)
and (x₂,y₂) points, Line
objects extend toward infinity.Plane
,
LinearTransformBuilder
,
Serialized FormDefined in the sis-utility
module
Constructor and Description |
---|
Line()
Constructs an uninitialized line.
|
Line(double slope,
double y0)
Constructs a line with the specified slope and offset.
|
Modifier and Type | Method and Description |
---|---|
Line |
clone()
Returns a clone of this line.
|
boolean |
equals(Object object)
Compares this line with the specified object for equality.
|
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.
|
double |
fit(Iterable<? extends DirectPosition> points)
Given a sequence of points, fits them to a straight line
y = slope⋅x + y₀ in a least-squares senses.
|
double |
fit(Vector x,
Vector 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.
|
int |
hashCode()
Returns a hash code value for this line.
|
void |
setEquation(double slope,
double y0)
Sets this line to the specified slope and offset.
|
void |
setEquation(Number slope,
Number y0)
Sets this line from values of arbitrary
Number type. |
void |
setFromPoints(double x1,
double y1,
double x2,
double y2)
Sets a line through the specified points.
|
double |
slope()
Returns the slope.
|
String |
toString()
Returns a string representation of this line.
|
void |
translate(double dx,
double dy)
Translates the line.
|
double |
x(double y)
Computes x = f⁻¹(y).
|
double |
x0()
Returns the x value for y = 0.
|
double |
y(double x)
Computes y = f(x).
|
double |
y0()
Returns the y value for x = 0.
|
public Line()
Double.NaN
.public Line(double slope, double y0)
slope
- the slope.y0
- the y value at x = 0.setEquation(double, double)
public final double x0()
public final double x(double y)
y
- the y value where to evaluate the inverse function.y(double)
public final double y0()
public final double y(double x)
x
- the x value where to evaluate the inverse function.x(double)
public void translate(double dx, double dy)
dx
- the horizontal translation.dy
- the vertical translation.public void setEquation(double slope, double y0)
slope
- the slope.y0
- the y value at x = 0.setFromPoints(double, double, double, double)
,
fit(double[], double[])
public void setEquation(Number slope, Number y0)
Number
type. This method is invoked by algorithms that
may produce other kind of numbers (for example with different precision) than the usual double
primitive type. The default implementation delegates to setEquation(double, double)
, but
subclasses can override this method if they want to process other kind of numbers in a special way.slope
- the slope.y0
- the y value at x = 0.public void setFromPoints(double x1, double y1, double x2, double y2)
x1
- ordinate x of the first point.y1
- ordinate y of the first point.x2
- ordinate x of the second point.y2
- ordinate y of the second point.public double fit(double[] x, double[] y)
The default implementation delegates to fit(Vector, Vector)
.
x
- vector of x values (independent variable).y
- vector of y values (dependent variable).IllegalArgumentException
- if x and y do not have the same length.public double fit(Vector x, Vector y)
The default implementation delegates to fit(Iterable)
.
x
- vector of x values (independent variable).y
- vector of y values (dependent variable).IllegalArgumentException
- if x and y do not have the same length.public double fit(Iterable<? extends DirectPosition> points)
Double.NaN
ordinate values are ignored.points
- the two-dimensional points.MismatchedDimensionException
- if a point is not two-dimensional.public Line clone()
public boolean equals(Object object)
public int hashCode()
Copyright © 2010–2017 The Apache Software Foundation. All rights reserved.