math.geom2d.line
Class AbstractLine2D

Package class diagram package AbstractLine2D
java.lang.Object
  extended by math.geom2d.curve.AbstractContinuousCurve2D
      extended by math.geom2d.curve.AbstractSmoothCurve2D
          extended by math.geom2d.line.AbstractLine2D
All Implemented Interfaces:
Serializable, Cloneable, CirculinearContinuousCurve2D, CirculinearCurve2D, CirculinearElement2D, CirculinearShape2D, ContinuousCirculinearCurve2D, ContinuousCurve2D, Curve2D, SmoothCurve2D, ContinuousOrientedCurve2D, OrientedCurve2D, SmoothOrientedCurve2D, LinearShape2D, Shape2D
Direct Known Subclasses:
InvertedRay2D, LineArc2D, LineSegment2D, Ray2D, StraightLine2D

public abstract class AbstractLine2D
extends AbstractSmoothCurve2D
implements SmoothOrientedCurve2D, LinearShape2D, CirculinearElement2D

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.

See Also:
Serialized Form

Field Summary
protected  double dx
          Direction vector of the line.
protected  double dy
          Direction vector of the line.
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.Shape2D
ACCURACY
 
Constructor Summary
protected AbstractLine2D(double x0, double y0, double dx, double dy)
           
protected AbstractLine2D(LinearShape2D line)
           
protected AbstractLine2D(Point2D point, Vector2D vector)
           
 
Method Summary
 CurveSet2D<? extends AbstractLine2D> clip(Box2D box)
          When a curve is clipped, the result is a set of curves.
abstract  AbstractLine2D clone()
          Ensures public declaration of clone(), and ensures valid return type.
 boolean contains(Point2D p)
          Checks if the shape contains the given point.
 CirculinearDomain2D getBuffer(double dist)
          Computes the buffer of the shape, formed by the set of points located at a distance from the shape that is lower or equal to d.
 double[] getCartesianEquation()
          Returns the coefficient of the Cartesian representation of the line.
 Collection<? extends AbstractLine2D> 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)
          Gets the distance of the StraightObject2d to the given point.
 double getDistance(Point2D p)
          Gets the distance of the StraightObject2d to the given point.
 double getHorizontalAngle()
          Gets Angle with axis (O,i), counted counter-clockwise.
static Point2D getIntersection(AbstractLine2D l1, AbstractLine2D l2)
          Returns the unique intersection of two straight objects.
 Point2D getIntersection(LinearShape2D line)
          Returns the unique intersection with a linear shape.
 Collection<Point2D> getIntersections(LinearShape2D line)
          Returns the intersection points of the curve with the specified line.
 double getLength()
           
 double getLength(double pos)
           
 Point2D getOrigin()
          Returns a point in the linear shape.
 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 polar coefficients.
 double getPosition(double length)
           
 double getPosition(Point2D point)
          Gets the position of the point on the line arc.
 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(Point2D p)
          Get the signed distance of the StraightObject2d to the given point.
 double[] getSignedPolarCoefficients()
          Returns the signed polar coefficients.
 Collection<? extends AbstractLine2D> getSmoothPieces()
          Return the intersection points of the curve with the specified line.
 AbstractLine2D getSubCurve(double t0, double t1)
          Returns a new AbstractLine2D, which is the portion of this AbstractLine2D delimited by parameters t0 and t1.
 StraightLine2D getSupportingLine()
           
 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 getTangent(double t)
           
 Vector2D getVector()
          Return one direction vector of the linear shape.
 double getWindingAngle(Point2D point)
          Return the angle portion that the curve turn around the given point.
 boolean isClosed()
          Always returns false, because we can not come back to starting point if we always go straight...
static boolean isColinear(AbstractLine2D line1, AbstractLine2D line2)
          Test if the two linear objects are located on the same straight line.
 boolean isColinear(LinearShape2D linear)
           
 boolean isEmpty()
          Returns false, unless both dx and dy equal 0.
 boolean isInside(Point2D p)
          Returns true if the given point lies to the left of the line when traveling along the line in the direction given by its direction vector.
static boolean isParallel(AbstractLine2D line1, AbstractLine2D line2)
          Test if the two linear objects are parallel.
 boolean isParallel(LinearShape2D line)
          Test if the this object is parallel to the given one.
 double project(Point2D point)
          Gets the position of the closest point on the line arc.
protected  boolean supportContains(double x, double y)
          Returns true if the point (x, y) lies on the line covering the object, with precision given by Shape2D.ACCURACY.
abstract  AbstractLine2D transform(AffineTransform2D transform)
          Transforms the curve by an affine transform.
 CirculinearElement2D transform(CircleInversion2D inv)
          Transforms the shape by a circle inversion.
 
Methods inherited from class math.geom2d.curve.AbstractSmoothCurve2D
getLeftTangent, getRightTangent, getSingularPoints, isSingular
 
Methods inherited from class math.geom2d.curve.AbstractContinuousCurve2D
draw, getAsAWTShape, getAsPolyline, getFirstPoint, getLastPoint, wrapCurve
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface math.geom2d.circulinear.CirculinearElement2D
getParallel, getReverseCurve
 
Methods inherited from interface math.geom2d.curve.ContinuousCurve2D
appendPath, getAsPolyline, getLeftTangent, getRightTangent
 
Methods inherited from interface math.geom2d.curve.Curve2D
draw, getAsAWTShape, getFirstPoint, getLastPoint, getPoint, getSingularPoints, getT0, getT1, isSingular
 
Methods inherited from interface math.geom2d.Shape2D
contains, getBoundingBox, isBounded
 

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

AbstractLine2D

protected AbstractLine2D(double x0,
                         double y0,
                         double dx,
                         double dy)

AbstractLine2D

protected AbstractLine2D(Point2D point,
                         Vector2D vector)

AbstractLine2D

protected AbstractLine2D(LinearShape2D line)
Method Detail

getIntersection

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


isColinear

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


isParallel

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


isColinear

public boolean isColinear(LinearShape2D linear)

isParallel

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


supportContains

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


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

Returns:
the array {a, b, c}.

getPolarCoefficients

public double[] getPolarCoefficients()
Returns polar coefficients.

Returns:
an array of 2 elements, the first one is the distance to the origin, the second one is the angle with horizontal, between 0 and 2*PI.

getSignedPolarCoefficients

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

Returns:
an array of 2 elements, the first one is the signed distance to the origin, the second one is the angle with horizontal, 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.


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

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

getOrigin

public Point2D getOrigin()
Description copied from interface: LinearShape2D
Returns a point in the linear shape.

Specified by:
getOrigin in interface LinearShape2D
Returns:
a point in the linear shape.

getVector

public Vector2D getVector()
Description copied from interface: LinearShape2D
Return one direction vector of the linear shape.

Specified by:
getVector in interface LinearShape2D
Returns:
a direction vector

getHorizontalAngle

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

Specified by:
getHorizontalAngle in interface LinearShape2D

getIntersection

public Point2D getIntersection(LinearShape2D line)
Returns the unique intersection with a linear shape. If the intersection doesn't exist (parallel lines), returns null.

Specified by:
getIntersection in interface LinearShape2D

getSupportingLine

public StraightLine2D getSupportingLine()
Specified by:
getSupportingLine in interface LinearShape2D

getBuffer

public CirculinearDomain2D getBuffer(double dist)
Description copied from interface: CirculinearShape2D
Computes the buffer of the shape, formed by the set of points located at a distance from the shape that is lower or equal to d.

Specified by:
getBuffer in interface CirculinearShape2D
Parameters:
dist - the maximal distance between a point of the buffer and the shape
Returns:
the buffer of the shape

getLength

public double getLength()
Specified by:
getLength in interface CirculinearCurve2D
Returns:
the length of the curve

getLength

public double getLength(double pos)
Specified by:
getLength in interface CirculinearCurve2D
Returns:
the length from the beginning to the position given by pos

getPosition

public double getPosition(double length)
Specified by:
getPosition in interface CirculinearCurve2D
Returns:
the position located at distance 'length' from the origin

transform

public CirculinearElement2D transform(CircleInversion2D inv)
Description copied from interface: CirculinearShape2D
Transforms the shape by a circle inversion. The result is still an instance a CirculinearShape2D.

Specified by:
transform in interface CirculinearContinuousCurve2D
Specified by:
transform in interface CirculinearCurve2D
Specified by:
transform in interface CirculinearElement2D
Specified by:
transform in interface CirculinearShape2D
Specified by:
transform in interface ContinuousCirculinearCurve2D
Parameters:
inv - the circle inversion
Returns:
the transformed shape

getWindingAngle

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

Specified by:
getWindingAngle in interface OrientedCurve2D
Parameters:
point - a point of the plane
Returns:
a signed angle

getSignedDistance

public double getSignedDistance(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 AbstractLine2D 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 AbstractLine2D 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)
Returns true if the given point lies to the left of the line when traveling along the line in the direction given by its direction vector.

Specified by:
isInside in interface OrientedCurve2D
Parameters:
p - the point to test
Returns:
true if point p lies on the 'left' of the line.

getTangent

public Vector2D getTangent(double t)
Specified by:
getTangent in interface SmoothCurve2D

getCurvature

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

Specified by:
getCurvature in interface SmoothCurve2D

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 Collection<? extends AbstractLine2D> getSmoothPieces()
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:
getSmoothPieces in interface CirculinearContinuousCurve2D
Specified by:
getSmoothPieces in interface ContinuousCirculinearCurve2D
Specified by:
getSmoothPieces in interface ContinuousCurve2D
Overrides:
getSmoothPieces in class AbstractSmoothCurve2D

getIntersections

public Collection<Point2D> getIntersections(LinearShape2D line)
Description copied from interface: Curve2D
Returns 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

getPosition

public double getPosition(Point2D point)
Gets the position of the point on the line arc. 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, returns Double.NaN.

Specified by:
getPosition in interface Curve2D
Parameters:
point - a point belonging to the curve
Returns:
the position of the point on the curve

project

public double project(Point2D point)
Gets the position of the closest point on the line arc. 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, returns t0, or t1, depending on which one is the closest.

Specified by:
project in interface Curve2D
Parameters:
point - a point to project
Returns:
the position of the closest orthogonal projection

getSubCurve

public AbstractLine2D getSubCurve(double t0,
                                  double t1)
Returns a new AbstractLine2D, which is the portion of this AbstractLine2D delimited by parameters t0 and t1. Casts the result to StraightLine2D, Ray2D or LineSegment2D when appropriate.

Specified by:
getSubCurve in interface CirculinearContinuousCurve2D
Specified by:
getSubCurve in interface CirculinearCurve2D
Specified by:
getSubCurve in interface CirculinearElement2D
Specified by:
getSubCurve in interface ContinuousCirculinearCurve2D
Specified by:
getSubCurve in interface ContinuousCurve2D
Specified by:
getSubCurve in interface Curve2D
Specified by:
getSubCurve in interface SmoothCurve2D
Specified by:
getSubCurve in interface ContinuousOrientedCurve2D
Specified by:
getSubCurve in interface SmoothOrientedCurve2D
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.

getContinuousCurves

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

Specified by:
getContinuousCurves in interface CirculinearCurve2D
Specified by:
getContinuousCurves in interface Curve2D
Overrides:
getContinuousCurves in class AbstractContinuousCurve2D
Returns:
a collection of continuous curves.

getDistance

public double getDistance(Point2D p)
Gets the distance of the StraightObject2d to the given point. This method is not designed to be used directly, because AbstractLine2D is an abstract class, but it can be called by subclasses to help computations.

Specified by:
getDistance in interface Shape2D

getDistance

public double getDistance(double x,
                          double y)
Gets the distance of the StraightObject2d to the given point. This method is not designed to be used directly, because AbstractLine2D is an abstract class, but it can be used by subclasses to help computations.

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

contains

public boolean contains(Point2D p)
Description copied from interface: Shape2D
Checks if the shape contains the given point.

Specified by:
contains in interface Shape2D

isEmpty

public boolean isEmpty()
Returns false, unless both dx and dy equal 0.

Specified by:
isEmpty in interface Shape2D
Returns:
true if the shape does not contain any point.

transform

public abstract AbstractLine2D 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 Curve2D
Specified by:
transform in interface SmoothCurve2D
Specified by:
transform in interface ContinuousOrientedCurve2D
Specified by:
transform in interface OrientedCurve2D
Specified by:
transform in interface SmoothOrientedCurve2D
Specified by:
transform in interface LinearShape2D
Specified by:
transform in interface Shape2D
Parameters:
transform - an affine transform
Returns:
the transformed shape

clip

public CurveSet2D<? extends AbstractLine2D> clip(Box2D box)
Description copied from interface: Curve2D
When a curve is clipped, the result is a set of curves.

Specified by:
clip in interface CirculinearContinuousCurve2D
Specified by:
clip in interface CirculinearCurve2D
Specified by:
clip in interface CirculinearElement2D
Specified by:
clip in interface ContinuousCirculinearCurve2D
Specified by:
clip in interface ContinuousCurve2D
Specified by:
clip in interface Curve2D
Specified by:
clip in interface SmoothCurve2D
Specified by:
clip in interface ContinuousOrientedCurve2D
Specified by:
clip in interface OrientedCurve2D
Specified by:
clip in interface SmoothOrientedCurve2D
Specified by:
clip in interface Shape2D
Parameters:
box - the clipping box
Returns:
the clipped shape

clone

public abstract AbstractLine2D clone()
Ensures public declaration of clone(), and ensures valid return type.

Specified by:
clone in interface Curve2D
Specified by:
clone in class AbstractSmoothCurve2D
Returns:
the cloned curve


Copyright © 2015 AMIS research group, Faculty of Mathematics and Physics, Charles University in Prague, Czech Republic. All Rights Reserved.