org.geotools.math
Class Line

java.lang.Object
  extended byorg.geotools.math.Line
All Implemented Interfaces:
java.lang.Cloneable, org.opengis.util.Cloneable, java.io.Serializable

public class Line
extends java.lang.Object
implements org.opengis.util.Cloneable, java.io.Serializable

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), objects extends toward infinity. The equation parameters for a object can bet set at construction time or using one of the 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
Version:
$Id: Line.java 17672 2006-01-19 00:25:55Z desruisseaux $
Author:
Martin Desruisseaux
See Also:
Point2D, Line2D, Plane, Serialized Form

Constructor Summary
Line()
          Construct an initially unitialized line.
Line(double slope, double y0)
          Construct a line with the specified slope and offset.
 
Method Summary
 java.lang.Object clone()
          Returns a clone of this line.
 boolean equals(java.lang.Object object)
          Compare this object with the specified one for equality.
 double getSlope()
          Returns the slope.
 double getX0()
          Returns the x value for y==0.
 double getY0()
          Returns the y value for x==0.
 int hashCode()
          Returns a hash code value for this line.
 java.awt.geom.Point2D intersectionPoint(Line line)
          Returns the intersection point between this line and the specified one.
 java.awt.geom.Point2D intersectionPoint(java.awt.geom.Line2D line)
          Returns the intersection point between this line and the specified bounded line.
 java.awt.geom.Line2D isoscelesTriangleBase(java.awt.geom.Point2D summit, double sideLength)
          Compute the base of a isosceles triangle having the specified summit and side length.
 java.awt.geom.Point2D nearestColinearPoint(java.awt.geom.Point2D point)
          Returns the nearest point on this line from the specified point.
 double setLine(double[] x, double[] y)
          Given a set of data points , , fit them to a straight line y=b+mx in a least-squares senses.
 void setLine(double slope, double y0)
          Set the slope and offset for this line.
 void setLine(java.awt.geom.Line2D line)
          Set a line colinear with the specified line segment.
 void setLine(java.awt.geom.Point2D p1, java.awt.geom.Point2D p2)
          Set a line through the specified point.
 java.lang.String toString()
          Returns a string representation of this line.
 void translate(double dx, double dy)
          Translate the line.
 double x(double y)
          Compute x=f-1(y).
 double y(double x)
          Compute y=f(x).
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Line

public Line()
Construct an initially unitialized line. All methods will returns Double.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:
setLine(double, double)
Method Detail

setLine

public void setLine(double slope,
                    double y0)
Set 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(Point2D, Point2D), setLine(Line2D), setLine(double[], double[])

setLine

public void setLine(java.awt.geom.Line2D line)
Set 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(Point2D,Point2D)

setLine

public void setLine(java.awt.geom.Point2D p1,
                    java.awt.geom.Point2D p2)
Set 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(Line2D)

setLine

public double setLine(double[] x,
                      double[] y)
               throws javax.vecmath.MismatchedSizeException
Given a set of data points , , 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:
javax.vecmath.MismatchedSizeException - if x and y don't have the same length.

translate

public void translate(double dx,
                      double dy)
Translate the line. The slope stay unchanged.

Parameters:
dx - The horizontal translation.
dy - The vertical translation.

y

public final double y(double x)
Compute 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(double)

x

public final double x(double y)
Compute 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:
y(double)

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

public java.awt.geom.Point2D intersectionPoint(Line line)
Returns the intersection point between this line and the specified one. If both lines are parallel, then this method returns .

Parameters:
line - The line to intersect.
Returns:
The intersection point, or .

intersectionPoint

public java.awt.geom.Point2D intersectionPoint(java.awt.geom.Line2D line)
Returns the intersection point between this line and the specified bounded line. If both lines are parallel or if the specified doesn't reach this line (since Line2D do not extends toward infinities), then this method returns .

Parameters:
line - The bounded line to intersect.
Returns:
The intersection point, or .

nearestColinearPoint

public java.awt.geom.Point2D nearestColinearPoint(java.awt.geom.Point2D point)
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 .

isoscelesTriangleBase

public java.awt.geom.Line2D isoscelesTriangleBase(java.awt.geom.Point2D summit,
                                                  double sideLength)
Compute 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:

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 if the base can't be computed. If non-null, then the triangle is the figure formed by joining (x1,y1), (x2,y2) and .

toString

public java.lang.String toString()
Returns a string representation of this line. This method returns the linear equation in the form "y=m*x+b".

Returns:
A string representation of this line.

equals

public boolean equals(java.lang.Object object)
Compare this object with the specified one for equality.


hashCode

public int hashCode()
Returns a hash code value for this line.


clone

public java.lang.Object clone()
Returns a clone of this line.

Specified by:
clone in interface org.opengis.util.Cloneable


Copyright © GeoTools. All Rights Reserved.