math.geom2d.line
Class LineObject2D

java.lang.Object
  extended by math.geom2d.line.StraightObject2D
      extended by math.geom2d.line.LineObject2D
All Implemented Interfaces:
java.awt.Shape, ContinuousCurve2D, ContinuousOrientedCurve2D, Curve2D, OrientedCurve2D, SmoothCurve2D, SmoothOrientedCurve2D, Shape2D

public class LineObject2D
extends StraightObject2D

Straight Object defined from 2 points. This object keep points reference in memory, then changing location of point obtained with getPoint2() or getPoint2() will change properties of line.

Moreover, type of object can change if one or both of the ending points are set to null. It is then an easy way represent Straight Lines, Edges or Rays in the same class. If both points exist, object is like an Edge2D. If one only the two points is set to null , it is like a Ray2D, with orientation depending one the missing point. If the two Points are set to null , then the object is like a StraightLine2D.

Example :

// Create an Edge2D
LineObject2D line = new LineObject2D(new Point2D(0, 0), new Point2D(1, 2));
// Change direction of line, by changing second point :
line.getPoint2().setLocation(4, 5);
// Change position and direction of the line, by changing second point. 'line' is
// now the edge (2,3)-(4,5)
line.setPoint1(new Point2D(2, 3));
// Transform into Ray2D :
line.setPoint1(null);
// Transform into Line2D, going through (2,3) and (4,5) :
line.setPoint2(null);

This class is maybe slower than Edge2D or StraightLine2D, because parameters are updated each time a computation is made, causing lot of additional processing.


Field Summary
 
Fields inherited from class math.geom2d.line.StraightObject2D
dx, dy, x0, y0
 
Fields inherited from interface math.geom2d.curve.ContinuousCurve2D
CIRCLE, CLOSED_EDGE, LOOP, OPEN_EDGE
 
Fields inherited from interface math.geom2d.Shape2D
ACCURACY, defaultClipWindow, EMPTY_SET
 
Constructor Summary
LineObject2D(double x1, double y1, double x2, double y2)
          Define a new Edge with two extremities.
LineObject2D(Point2D point1, Point2D point2)
          Define a new Edge with two extremities.
 
Method Summary
 java.awt.geom.GeneralPath appendPath(java.awt.geom.GeneralPath path)
          Append the path of the curve to the given path.
 CurveSet2D<? extends LineArc2D> clip(Box2D box)
          Clip the line object by a box.
 boolean contains(double x, double y)
          Return true if the point (x, y) lies on the line, with precision given by Shape2D.ACCURACY.
 boolean contains(double x, double y, double w, double h)
          Return false, because an line cannot contain a rectangle.
 boolean contains(java.awt.geom.Point2D p)
          Return true if the point p lies on the line, with precision given by Shape2D.ACCURACY.
 boolean equals(LineObject2D edge)
          Two LineObject2D are equals if the share the two same points, in the same order.
 boolean equals(java.lang.Object obj)
           
 Polyline2D getAsPolyline(int n)
          Returns an approximation of the curve as a polyline with n line segments.
 ContinuousOrientedCurve2D[] getBoundaryCurves()
           
 Box2D getBoundingBox()
          Return more precise bounds for the LineObject.
 java.awt.Rectangle getBounds()
          Return bounding box of the shape.
 java.awt.geom.Rectangle2D getBounds2D()
          Return more precise bounds for the shape.
 double[] getCartesianEquation()
          Returns the coefficient of the cartesian representation of the line.
 Shape2D getClippedShape(Box2D box)
           
 java.util.Collection<ContinuousCurve2D> getContinuousCurves()
          Returns the collection of continuous curves which constitute this curve.
 double getCurvature(double t)
          returns 0 as every straight object.
 double getDistance(double x, double y)
          Get the distance of the point (x, y) to this edge.
 double getDistance(java.awt.geom.Point2D p)
          Get the distance of the point (x, y) to this edge.
 Point2D getFirstPoint()
          Get the first point of the curve.
 double getHorizontalAngle()
          Gets Angle with axis (O,i), counted counter-clockwise.
 java.awt.geom.GeneralPath getInnerPath()
           
 Point2D getLastPoint()
          Get the last point of the curve.
 double getLength()
          Returns the length of the edge.
 Point2D getOtherPoint(Point2D point)
          Return the opposite vertex of the edge.
 StraightLine2D getParallel(Point2D point)
          Create a straight line parallel to this object, and going through the given point.
 double[][] getParametric()
          Returns the matrix of parametric representation of the line.
 java.awt.geom.PathIterator getPathIterator(java.awt.geom.AffineTransform t)
          Return pathiterator for this edge.
 java.awt.geom.PathIterator getPathIterator(java.awt.geom.AffineTransform t, double flatness)
          Return pathiterator for this edge.
 StraightLine2D getPerpendicular(Point2D point)
          Create a straight line perpendicular to this object, and going through the given point.
 Point2D getPoint(double t)
          Gets the point from a parametric representation of the curve.
 Point2D getPoint(double t, Point2D point)
          Same as getPoint(t), but gives the point as a parameter.
 Point2D getPoint1()
          Return the first point of the edge.
 Point2D getPoint2()
          Return the last point of the edge.
 double[] getPolarCoefficients()
          Returns two coefficients : the minimal distance between the straight line covering this object and the origin, and the angle of object with horizontal.
 double getPosition(Point2D point)
          Gets position of the point on the line.
 Point2D getProjectedPoint(double x, double y)
          Return the projection of point p on the line.
 Point2D getProjectedPoint(Point2D p)
          Return the projection of point p on the line.
 LineObject2D getReverseCurve()
          return the line object which starts at point2 and ends at point1.
 double getSignedDistance(double x, double y)
          Get the signed distance of the StraightObject2d to the given point.
 double getSignedDistance(java.awt.geom.Point2D p)
          Get the signed distance of the StraightObject2d to the given point.
 double[] getSignedPolarCoefficients()
          Returns the polar coefficients, but distance to origin can be negative : this allows representation of directed lines.
 java.util.Collection<? extends SmoothCurve2D> getSmoothPieces()
          Returns an array containing the curve itself.
 LineArc2D getSubCurve(double t0, double t1)
          Return a new LineArc2D, which is the portion of the linearc delimited by parameters t0 and t1.
 double getT0()
          Returns the parameter of the first point of the line Object.
 double getT1()
          Returns the parameter of the first point of the line Object.
 Vector2D getTangent(double t)
           
 double getWindingAngle(java.awt.geom.Point2D point)
          Return the angle portion that the curve turn around the given point.
 double getX1()
           
 double getX2()
           
 double getY1()
           
 double getY2()
           
 boolean intersects(double x, double y, double w, double h)
          Tests if the Line intersects the interior of a specified rectangular area.
 boolean intersects(java.awt.geom.Rectangle2D r)
          Tests if the Line intersects the interior of a specified rectangle2D.
 boolean isBounded()
          return true only if both point1 and point2 are not set to null.
 boolean isColinear(StraightObject2D line)
           
 boolean isInside(java.awt.geom.Point2D point)
          return true if the point is 'inside' the domain bounded by the curve.
 boolean isParallel(StraightObject2D line)
          Test if the this object is parallel to the given one.
 boolean isPositivelyOriented(Point2D point)
           
 double project(Point2D point)
          Returns the position of the closest orthogonal projection of the point on the curve, or of the closest singular point.
 void setPoint1(Point2D point)
           
 void setPoint2(Point2D point)
           
 java.lang.String toString()
           
 LineObject2D transform(AffineTransform2D trans)
          Transforms the curve by an affine transform.
 
Methods inherited from class math.geom2d.line.StraightObject2D
contains, getDistance, getIntersection, getIntersection, getIntersections, getOrigin, getPositionOnLine, getPositionOnLine, getSupportLine, getSymmetric, getSymmetric, getVector, isClosed, isColinear, isInside, isParallel
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

LineObject2D

public LineObject2D(Point2D point1,
                    Point2D point2)
Define a new Edge with two extremities.


LineObject2D

public LineObject2D(double x1,
                    double y1,
                    double x2,
                    double y2)
Define a new Edge with two extremities.

Method Detail

isBounded

public boolean isBounded()
return true only if both point1 and point2 are not set to null. If one of the two points is null, it is a Ray. If both points are set to null, it is a Straight Line.


isColinear

public boolean isColinear(StraightObject2D line)
Overrides:
isColinear in class StraightObject2D

isParallel

public boolean isParallel(StraightObject2D line)
Test if the this object is parallel to the given one. This method is overloaded to update parameters before computation.

Overrides:
isParallel in class StraightObject2D

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

equals

public boolean equals(LineObject2D edge)
Two LineObject2D are equals if the share the two same points, in the same order.

Parameters:
edge - : the edge to compare to.
Returns:
true if extremities of both edges are the same.

getDistance

public double getDistance(java.awt.geom.Point2D p)
Get the distance of the point (x, y) to this edge.


getDistance

public double getDistance(double x,
                          double y)
Get the distance of the point (x, y) to this edge.

Specified by:
getDistance in interface Shape2D
Overrides:
getDistance in class StraightObject2D
Parameters:
x - , y : position of point
Returns:
distance between this object and the point (x,y)

getSignedDistance

public double getSignedDistance(java.awt.geom.Point2D p)
Description copied from class: StraightObject2D
Get the signed distance of the StraightObject2d to the given point. The signed distance is positive if point lies 'to the right' of the line, when moving in the direction given by direction vector. This method is not designed to be used directly, because StraightObject2D is an abstract class, but it can be used by subclasses to help computations.

Specified by:
getSignedDistance in interface OrientedCurve2D
Overrides:
getSignedDistance in class StraightObject2D
Parameters:
p - a point of the plane
Returns:
the signed distance to the curve

getSignedDistance

public double getSignedDistance(double x,
                                double y)
Description copied from class: StraightObject2D
Get the signed distance of the StraightObject2d to the given point. The signed distance is positive if point lies 'to the right' of the line, when moving in the direction given by direction vector. This method is not designed to be used directly, because StraightObject2D is an abstract class, but it can be used by subclasses to help computations.

Specified by:
getSignedDistance in interface OrientedCurve2D
Overrides:
getSignedDistance in class StraightObject2D
Parameters:
x - x-coord of a point
y - y-coord of a point
Returns:
the signed distance of the point (x,y) to the curve

isPositivelyOriented

public boolean isPositivelyOriented(Point2D point)

getParametric

public double[][] getParametric()
Description copied from class: StraightObject2D
Returns the matrix of parametric representation of the line. Result has the form :

[ x0 dx ]

[ y0 dy ]

It can be easily extended to higher dimensions and/or higher polynomial forms.

Overrides:
getParametric in class StraightObject2D

getCartesianEquation

public double[] getCartesianEquation()
Description copied from class: StraightObject2D
Returns the coefficient of the cartesian representation of the line. Cartesian equation has the form : ax+by+c=0. The returned array is {a, b, c}.

Overrides:
getCartesianEquation in class StraightObject2D

getPolarCoefficients

public double[] getPolarCoefficients()
Description copied from class: StraightObject2D
Returns two coefficients : the minimal distance between the straight line covering this object and the origin, and the angle of object with horizontal.

Overrides:
getPolarCoefficients in class StraightObject2D

getSignedPolarCoefficients

public double[] getSignedPolarCoefficients()
Description copied from class: StraightObject2D
Returns the polar coefficients, but distance to origin can be negative : this allows representation of directed lines.

Overrides:
getSignedPolarCoefficients in class StraightObject2D

getHorizontalAngle

public double getHorizontalAngle()
Description copied from class: StraightObject2D
Gets Angle with axis (O,i), counted counter-clockwise. Result is given between 0 and 2*pi.

Overrides:
getHorizontalAngle in class StraightObject2D

getProjectedPoint

public Point2D getProjectedPoint(Point2D p)
Description copied from class: StraightObject2D
Return the projection of point p on the line. The returned point can be used to compute distance from point to line.

Overrides:
getProjectedPoint in class StraightObject2D
Parameters:
p - a point outside the line (if point p lies on the line, it is returned)
Returns:
the projection of the point p on the line

getProjectedPoint

public Point2D getProjectedPoint(double x,
                                 double y)
Description copied from class: StraightObject2D
Return the projection of point p on the line. The returned point can be used to compute distance from point to line.

Overrides:
getProjectedPoint in class StraightObject2D
Parameters:
x - : coordinate x of point to be projected
y - : coordinate y of point to be projected
Returns:
the projection of the point p on the line

getParallel

public StraightLine2D getParallel(Point2D point)
Create a straight line parallel to this object, and going through the given point.

Overrides:
getParallel in class StraightObject2D
Parameters:
point - the point to go through
Returns:
the parallel through the point

getPerpendicular

public StraightLine2D getPerpendicular(Point2D point)
Create a straight line perpendicular to this object, and going through the given point.

Overrides:
getPerpendicular in class StraightObject2D
Parameters:
point - : the point to go through
Returns:
the perpendicular through point

getClippedShape

public Shape2D getClippedShape(Box2D box)

clip

public CurveSet2D<? extends LineArc2D> clip(Box2D box)
Clip the line object by a box. The result is an instance of CurveSet2D, which contains only instances of LineArc2D. If the line object is not clipped, the result is an instance of CurveSet2D which contains 0 curves.

Parameters:
box - the clipping box
Returns:
the clipped shape

getBoundingBox

public Box2D getBoundingBox()
Return more precise bounds for the LineObject. Return an instance of HRectangle2D.

Returns:
the bounding box of the shape.

getLength

public double getLength()
Returns the length of the edge.


getPoint1

public Point2D getPoint1()
Return the first point of the edge. It corresponds to getPoint(0).

Returns:
the first point.

getPoint2

public Point2D getPoint2()
Return the last point of the edge. It corresponds to getPoint(1).

Returns:
the last point.

getX1

public double getX1()

getY1

public double getY1()

getX2

public double getX2()

getY2

public double getY2()

getOtherPoint

public Point2D getOtherPoint(Point2D point)
Return the opposite vertex of the edge.

Parameters:
point - : one of the vertices of the edge
Returns:
the other vertex

getTangent

public Vector2D getTangent(double t)

getCurvature

public double getCurvature(double t)
returns 0 as every straight object.


getAsPolyline

public Polyline2D getAsPolyline(int n)
Description copied from interface: ContinuousCurve2D
Returns an approximation of the curve as a polyline with n line segments. If the curve is closed, the method should return an instance of ClosedPolyline2D.

Parameters:
n - the number of line segments
Returns:
a closed polyline with n line segments.

getSmoothPieces

public java.util.Collection<? extends SmoothCurve2D> getSmoothPieces()
Returns an array containing the curve itself.

Specified by:
getSmoothPieces in interface ContinuousCurve2D
Overrides:
getSmoothPieces in class StraightObject2D

getBoundaryCurves

public ContinuousOrientedCurve2D[] getBoundaryCurves()

getWindingAngle

public double getWindingAngle(java.awt.geom.Point2D point)
Description copied from interface: OrientedCurve2D
Return the angle portion that the curve turn around the given point. Result is a signed angle.

Parameters:
point - a point of the plane
Returns:
a signed angle

isInside

public boolean isInside(java.awt.geom.Point2D point)
Description copied from interface: OrientedCurve2D
return true if the point is 'inside' the domain bounded by the curve.

Parameters:
point - a point in the plane
Returns:
true if the point is on the left side of the curve.

getT0

public double getT0()
Returns the parameter of the first point of the line Object. It is equal to 0 in the case of edge or positive Rays, and equals -Infinity in the case of StraightLine or negative rays.


getT1

public double getT1()
Returns the parameter of the first point of the line Object. It is equal to 1 in the case of edge or negative Rays, and equals +Infinity in the case of StraightLine or positive rays.


getPoint

public Point2D getPoint(double t)
Description copied from interface: Curve2D
Gets the point from a parametric representation of the curve. If the parameter lies outside the definition range, the parameter corresponding to the closest bound is used instead. This method can be used to draw an approximated outline of a curve, by selecting multiple values for t and drawing lines between them.


getPoint

public Point2D getPoint(double t,
                        Point2D point)
Description copied from interface: Curve2D
Same as getPoint(t), but gives the point as a parameter. This avoids repetitive memory allocations.


getFirstPoint

public Point2D getFirstPoint()
Get the first point of the curve.

Returns:
the first point of the curve

getLastPoint

public Point2D getLastPoint()
Get the last point of the curve.

Returns:
the last point of the curve.

getPosition

public double getPosition(Point2D point)
Gets position of the point on the line. If point belongs to the line, this position is defined by the ratio :

t = (xp - x0)/dx <\code>, or equivalently :

t = (yp - y0)/dy <\code>.

If point does not belong to edge, return Double.NaN. The current implementation uses the direction with the biggest derivative, in order to avoid divisions by zero.

Parameters:
point - a point belonging to the curve
Returns:
the position of the point on the curve

project

public double project(Point2D point)
Description copied from interface: Curve2D
Returns the position of the closest orthogonal projection of the point on the curve, or of the closest singular point. This function should always returns a valid value.

Parameters:
point - a point to project
Returns:
the position of the closest orthogonal projection

getReverseCurve

public LineObject2D getReverseCurve()
return the line object which starts at point2 and ends at point1.


getContinuousCurves

public java.util.Collection<ContinuousCurve2D> getContinuousCurves()
Description copied from interface: Curve2D
Returns the collection of continuous curves which constitute this curve.

Returns:
a collection of continuous curves.

getSubCurve

public LineArc2D getSubCurve(double t0,
                             double t1)
Return a new LineArc2D, which is the portion of the linearc delimited by parameters t0 and t1.

Parameters:
t0 - position of the start of the sub-curve
t1 - position of the end of the sub-curve
Returns:
the portion of original curve comprised between t0 and t1.

setPoint1

public void setPoint1(Point2D point)

setPoint2

public void setPoint2(Point2D point)

contains

public boolean contains(double x,
                        double y)
Return true if the point (x, y) lies on the line, with precision given by Shape2D.ACCURACY.

Specified by:
contains in interface java.awt.Shape
Overrides:
contains in class StraightObject2D

contains

public boolean contains(double x,
                        double y,
                        double w,
                        double h)
Return false, because an line cannot contain a rectangle.

Specified by:
contains in interface java.awt.Shape
Overrides:
contains in class StraightObject2D

contains

public boolean contains(java.awt.geom.Point2D p)
Return true if the point p lies on the line, with precision given by Shape2D.ACCURACY.


getBounds

public java.awt.Rectangle getBounds()
Return bounding box of the shape.


getBounds2D

public java.awt.geom.Rectangle2D getBounds2D()
Return more precise bounds for the shape.


getInnerPath

public java.awt.geom.GeneralPath getInnerPath()

appendPath

public java.awt.geom.GeneralPath appendPath(java.awt.geom.GeneralPath path)
Description copied from interface: ContinuousCurve2D
Append the path of the curve to the given path.

Parameters:
path - a path to modify
Returns:
the modified path

getPathIterator

public java.awt.geom.PathIterator getPathIterator(java.awt.geom.AffineTransform t)
Return pathiterator for this edge.


getPathIterator

public java.awt.geom.PathIterator getPathIterator(java.awt.geom.AffineTransform t,
                                                  double flatness)
Return pathiterator for this edge.


intersects

public boolean intersects(double x,
                          double y,
                          double w,
                          double h)
Tests if the Line intersects the interior of a specified rectangular area.


intersects

public boolean intersects(java.awt.geom.Rectangle2D r)
Tests if the Line intersects the interior of a specified rectangle2D.


transform

public LineObject2D transform(AffineTransform2D trans)
Description copied from interface: Curve2D
Transforms the curve by an affine transform. The result is an instance of Curve2D.

Specified by:
transform in interface ContinuousCurve2D
Specified by:
transform in interface ContinuousOrientedCurve2D
Specified by:
transform in interface Curve2D
Specified by:
transform in interface OrientedCurve2D
Specified by:
transform in interface SmoothCurve2D
Specified by:
transform in interface SmoothOrientedCurve2D
Specified by:
transform in interface Shape2D
Specified by:
transform in class StraightObject2D
Parameters:
trans - an affine transform
Returns:
the transformed shape

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object