math.geom2d.line
Class StraightObject2D

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

public abstract class StraightObject2D
extends java.lang.Object
implements SmoothOrientedCurve2D

Base class for straight curves, such as straight lines, rays, or edges.

Internal representation of straight objects is parametric : (x0, y0) is a point in the object, and (dx, dy) is a direction vector of the line.

If the line is defined by two point, we can set (x0,y0) to the first point, and (dx,dy) to the vector (p1, p2).

Then, coordinates for a point (x,y) such as x=x0+t*dx and y=y0+t=dy, t between 0 and 1 give a point inside p1 and p2, t<0 give a point 'before' p1, and t>1 give a point 'after' p2, so it is convenient to easily manage edges, rays and straight lines.

At the difference of LineArc2D, this class is not necessarily connex (it can be the union of several colinear line segments).


Field Summary
protected  double dx
          Direction vector of the line. dx and dy should not be both zero.
protected  double dy
          Direction vector of the line. dx and dy should not be both zero.
protected  double x0
          Coordinates of starting point of the line
protected  double y0
          Coordinates of starting point of the line
 
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
StraightObject2D()
           
 
Method Summary
 boolean contains(double x, double y)
          Returns true if the point (x, y) lies on the line covering the object, with precision given by Shape2D.ACCURACY.
 boolean contains(double x, double y, double w, double h)
          Returns false, because a line cannot contain a rectangle.
 boolean contains(java.awt.geom.Rectangle2D r)
          Returns false, because a line cannot contain a rectangle.
 double[] getCartesianEquation()
          Returns the coefficient of the cartesian representation of the line.
 double getDistance(double x, double y)
          Get the distance of the StraightObject2d to the given point.
 double getDistance(Point2D p)
          Get the distance of the StraightObject2d to the given point.
 double getHorizontalAngle()
          Gets Angle with axis (O,i), counted counter-clockwise.
 Point2D getIntersection(StraightObject2D line)
          Returns the unique intersection with a straight object.
static Point2D getIntersection(StraightObject2D l1, StraightObject2D l2)
          Returns the unique intersection of two straight objects.
 java.util.Collection<Point2D> getIntersections(StraightObject2D line)
          Return the intersection points of the curve with the specified line.
 Point2D getOrigin()
           
 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.
 StraightLine2D getPerpendicular(Point2D point)
          Create a straight line perpendicular to this object, and going through the given point.
 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 getPositionOnLine(double x, double y)
          Compute position on the line, that is the number t such that if the point belong to the line, it location is given by x=x0+t*dx and y=y0+t*dy.
 double getPositionOnLine(Point2D point)
           
 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.
 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 a set of smooth curves.
 StraightLine2D getSupportLine()
          returns one straight line which contains this straight object.
 Point2D getSymmetric(double x, double y)
          Return the symmetric of point with coordinate (x, y) relative to this straight line.
 Point2D getSymmetric(Point2D p)
          Return the symmetric of point p relative to this straight line.
 Vector2D getVector()
           
 boolean isClosed()
          Always returns false, because we can not come back to starting point if we always go straight ...
 boolean isColinear(StraightObject2D line)
           
static boolean isColinear(StraightObject2D line1, StraightObject2D line2)
          Test if the two linear objects are located on the same straight line.
 boolean isInside(Point2D p)
          return true if the given point lies to the left of the line when travelling along the line in the direcion given by its direction vector.
 boolean isParallel(StraightObject2D line)
          Test if the this object is parallel to the given one.
static boolean isParallel(StraightObject2D line1, StraightObject2D line2)
          Test if the two linear objects are parallel.
abstract  StraightObject2D transform(AffineTransform2D transform)
          Transforms the curve by an affine transform.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface math.geom2d.curve.SmoothOrientedCurve2D
clip, getReverseCurve, getSubCurve
 
Methods inherited from interface math.geom2d.curve.SmoothCurve2D
getCurvature, getTangent
 
Methods inherited from interface math.geom2d.curve.ContinuousCurve2D
appendPath, getAsPolyline
 
Methods inherited from interface math.geom2d.curve.OrientedCurve2D
getWindingAngle, isInside
 
Methods inherited from interface math.geom2d.curve.Curve2D
getContinuousCurves, getFirstPoint, getLastPoint, getPoint, getPoint, getPosition, getT0, getT1, project
 
Methods inherited from interface math.geom2d.Shape2D
getBoundingBox, getDistance, isBounded
 
Methods inherited from interface java.awt.Shape
contains, getBounds, getBounds2D, getPathIterator, getPathIterator, intersects, intersects
 

Field Detail

x0

protected double x0
Coordinates of starting point of the line


y0

protected double y0
Coordinates of starting point of the line


dx

protected double dx
Direction vector of the line. dx and dy should not be both zero.


dy

protected double dy
Direction vector of the line. dx and dy should not be both zero.

Constructor Detail

StraightObject2D

public StraightObject2D()
Method Detail

getIntersection

public static final Point2D getIntersection(StraightObject2D l1,
                                            StraightObject2D l2)
Returns the unique intersection of two straight objects. If intersection doesn't exist (parallel lines), return null.


isColinear

public static final boolean isColinear(StraightObject2D line1,
                                       StraightObject2D line2)
Test if the two linear objects are located on the same straight line.


isParallel

public static final boolean isParallel(StraightObject2D line1,
                                       StraightObject2D line2)
Test if the two linear objects are parallel.


getOrigin

public Point2D getOrigin()

getVector

public Vector2D getVector()

isColinear

public boolean isColinear(StraightObject2D line)

isParallel

public boolean isParallel(StraightObject2D line)
Test if the this object is parallel to the given one.


isClosed

public boolean isClosed()
Always returns false, because we can not come back to starting point if we always go straight ...

Specified by:
isClosed in interface ContinuousCurve2D

getSmoothPieces

public java.util.Collection<? extends SmoothCurve2D> getSmoothPieces()
Returns a set of smooth curves. Actually, return the curve itself.

Specified by:
getSmoothPieces in interface ContinuousCurve2D

getDistance

public double getDistance(Point2D p)
Get the distance of the StraightObject2d to the given point. 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.


getDistance

public double getDistance(double x,
                          double y)
Get the distance of the StraightObject2d to the given point. 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:
getDistance in interface Shape2D
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)
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
Parameters:
p - a point of the plane
Returns:
the signed distance to the curve

getSignedDistance

public double getSignedDistance(double x,
                                double y)
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
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

isInside

public boolean isInside(Point2D p)
return true if the given point lies to the left of the line when travelling along the line in the direcion given by its direction vector.

Parameters:
p - the point to test
Returns:
true if point p lies on the 'left' of the line.

getParametric

public double[][] getParametric()
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.


getCartesianEquation

public double[] getCartesianEquation()
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}.


getPolarCoefficients

public 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.


getSignedPolarCoefficients

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


getHorizontalAngle

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


getPositionOnLine

public double getPositionOnLine(Point2D point)

getPositionOnLine

public double getPositionOnLine(double x,
                                double y)
Compute position on the line, that is the number t such that if the point belong to the line, it location is given by x=x0+t*dx and y=y0+t*dy.

If the point does not belong to the line, the method returns the position of its projection on the line.


getIntersections

public java.util.Collection<Point2D> getIntersections(StraightObject2D line)
Return the intersection points of the curve with the specified line. The length of the result array is the number of intersection points.

Specified by:
getIntersections in interface Curve2D

getIntersection

public Point2D getIntersection(StraightObject2D line)
Returns the unique intersection with a straight object. If intersection doesn't exist (parallel lines), return null.


getProjectedPoint

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

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

getSupportLine

public StraightLine2D getSupportLine()
returns one straight line which contains this straight object.

Returns:
the Straight line which contains this object

getProjectedPoint

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

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

getSymmetric

public Point2D getSymmetric(Point2D p)
Return the symmetric of point p relative to this straight line.

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

getSymmetric

public Point2D getSymmetric(double x,
                            double y)
Return the symmetric of point with coordinate (x, y) relative to this straight line.

Parameters:
x - : coordinate x of point to be projected
y - : coordinate y of point to be projected
Returns:
the projection of the point (x,y) on the line

getParallel

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

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.

Parameters:
point - the point to go through
Returns:
the perpendicular through the point

contains

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

Specified by:
contains in interface java.awt.Shape

contains

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

Specified by:
contains in interface java.awt.Shape

contains

public boolean contains(java.awt.geom.Rectangle2D r)
Returns false, because a line cannot contain a rectangle.

Specified by:
contains in interface java.awt.Shape

transform

public abstract StraightObject2D transform(AffineTransform2D transform)
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
Parameters:
transform - an affine transform
Returns:
the transformed shape