Package org.geotools.metadata.math
Class Line
Object
Line
- All Implemented Interfaces:
Serializable
,Cloneable
,Cloneable
Equation of a line in a two dimensional space (x,y). A line has an equation of the form
y=ax+b. At the difference of
Line2D
(which are bounded by
(x1,y1) and (x2,y2) points), Line
objects extends toward
infinity.
The equation parameters for a Line
object can bet 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)
compute the converse and should work even if the line is vertical.
- Since:
- 2.0
- Author:
- Martin Desruisseaux (PMO, IRD)
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionclone()
Returns a clone of this line.boolean
Compares this object with the specified one for equality.final double
getSlope()
Returns the slope.final double
getX0()
Returns the x value for y==0.final double
getY0()
Returns the y value for x==0.int
hashCode()
Returns a hash code value for this line.intersectionPoint
(Line2D line) Returns the intersection point between this line and the specified bounded line.intersectionPoint
(Line line) Returns the intersection point between this line and the specified one.isoscelesTriangleBase
(Point2D summit, double sideLength) Computes the base of a isosceles triangle having the specified summit and side length.nearestColinearPoint
(Point2D point) Returns the nearest point on this line from the specified point.double
setLine
(double[] x, double[] y) Given a set of data pointsx[0..ndata-1]
,y[0..ndata-1]
, fit them to a straight line y=b+mx in a least-squares senses.void
setLine
(double slope, double y0) Sets the slope and offset for this line.void
Sets a line colinear with the specified line segment.void
Sets a line through the specified point.toString()
Returns a string representation of this line.void
translate
(double dx, double dy) Translates the line.final double
x
(double y) Computes x=f-1(y).final double
y
(double x) Computes y=f(x).
-
Constructor Details
-
Line
public Line()Construct an initially unitialized line. All methods will returnsDouble.NaN
. -
Line
public Line(double slope, double y0) Construct a line with the specified slope and offset. The linear equation will be y=slope*x+y0.- Parameters:
slope
- The slope.y0
- The y value at x==0.- See Also:
-
-
Method Details
-
setLine
public void setLine(double slope, double y0) Sets the slope and offset for this line. The linear equation will be y=slope*x+y0.- Parameters:
slope
- The slope.y0
- The y value at x==0.- See Also:
-
setLine
Sets a line colinear with the specified line segment. The line will continues toward infinity after the line segment extremities.- Parameters:
line
- The line segment.- See Also:
-
setLine
Sets a line through the specified point. The line will continues toward infinity after the point.- Parameters:
p1
- Coordinate of the first point.p2
- Coordinate of the second point.- See Also:
-
setLine
Given a set of data pointsx[0..ndata-1]
,y[0..ndata-1]
, fit them to a straight line y=b+mx in a least-squares senses. This method assume that the x values are precise and all uncertainty is in y.Reference: Linear Regression Curve Fitting.
- Parameters:
x
- Vector of x values (independant variable).y
- Vector of y values (dependant variable).- Returns:
- Estimation of the correlation coefficient. The closer this coefficient is to 1, the better the fit.
- Throws:
MismatchedSizeException
- if x and y don't have the same length.IllegalArgumentException
-
translate
public void translate(double dx, double dy) Translates the line. The slope stay unchanged.- Parameters:
dx
- The horizontal translation.dy
- The vertical translation.
-
y
public final double y(double x) Computes y=f(x). If the line is vertical, then this method returns an infinite value. This method is final for performance reason.- Parameters:
x
- The x value.- Returns:
- The y value.
- See Also:
-
x
public final double x(double y) Computes x=f-1(y). If the line is horizontal, then this method returns an infinite value. This method is final for performance reason.- Parameters:
y
- The y value.- Returns:
- The x value.
- See Also:
-
getY0
public final double getY0()Returns the y value for x==0. Coordinate (0, y0) is the intersection point with the y axis. -
getX0
public final double getX0()Returns the x value for y==0. Coordinate (x0,0) is the intersection point with the x axis. -
getSlope
public final double getSlope()Returns the slope. -
intersectionPoint
Returns the intersection point between this line and the specified one. If both lines are parallel, then this method returnsnull
.- Parameters:
line
- The line to intersect.- Returns:
- The intersection point, or
null
.
-
intersectionPoint
Returns the intersection point between this line and the specified bounded line. If both lines are parallel or if the specifiedline
doesn't reach this line (sinceLine2D
do not extends toward infinities), then this method returnsnull
.- Parameters:
line
- The bounded line to intersect.- Returns:
- The intersection point, or
null
.
-
nearestColinearPoint
Returns the nearest point on this line from the specified point.- Parameters:
point
- An arbitrary point.- Returns:
- The point on this line which is the nearest of the specified
point
.
-
isoscelesTriangleBase
Computes the base of a isosceles triangle having the specified summit and side length. The base will be colinear with this line. In other words, this method compute two points (x1,y1) and (x2,y2) located in such a way that:- Both points are on this line.
- The distance between any of the two points and the specified
summit
is exactlysideLength
.
- Parameters:
summit
- The summit of the isosceles triangle.sideLength
- The length for the two sides of the isosceles triangle.- Returns:
- The base of the isoscele triangle, colinear with this line, or
null
if the base can't be computed. If non-null, then the triangle is the figure formed by joining (x1,y1), (x2,y2) andsummit
.
-
toString
Returns a string representation of this line. This method returns the linear equation in the form"y=m*x+b"
. -
equals
Compares this object with the specified one for equality. -
hashCode
public int hashCode()Returns a hash code value for this line. -
clone
Returns a clone of this line.
-