math.geom2d.line
Class Line2D

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

public class Line2D
extends AbstractSmoothCurve2D
implements LinearShape2D, CirculinearElement2D, Cloneable

Line object defined from 2 points. This object keep points reference in memory, and recomputes properties directly from points. Line2D is mutable.

Example :

// Create an Edge2D
Line2D line = new Line2D(new Point2D(0, 0), new Point2D(1, 2));
// Change direction of line, by changing second point :
line.setPoint2(new Point2D(4, 5));
// Change position and direction of the line, by changing first point.
// 'line' is now the edge (2,3)-(4,5)
line.setPoint1(new Point2D(2, 3));

This class may be slower than Edge2D or StraightLine2D, because parameters are updated each time a computation is made, causing lot of additional processing. Moreover, as inner point fields are public, it is not as safe as LineSegment2D.

See Also:
Serialized Form

Field Summary
 Point2D p1
          The origin point.
 Point2D p2
          The destination point.
 
Fields inherited from interface math.geom2d.Shape2D
ACCURACY
 
Constructor Summary
Line2D(double x1, double y1, double x2, double y2)
          Define a new Line2D with two extremities.
Line2D(Point2D point1, Point2D point2)
          Define a new Line2D with two extremities.
 
Method Summary
 GeneralPath appendPath(GeneralPath path)
          Append the path of the curve to the given path.
 CurveSet2D<? extends Line2D> clip(Box2D box)
          Clip the line object by a box.
 Line2D clone()
          Overrides Object declaration to ensure Curve2D implementation are cloned as Curve2D.
 boolean contains(double x, double y)
          Returns true if the point (x, y) lies on the line, with precision given by Shape2D.ACCURACY.
 boolean contains(Point2D p)
          Returns true if the point p lies on the line, with precision given by Shape2D.ACCURACY.
static Line2D create(Point2D p1, Point2D p2)
          Static factory for creating a new Line2D, starting from p1 and finishing at p2.
 boolean equals(Object obj)
          Two Line2D are equals if the share the two same points, in the same order.
 Box2D getBoundingBox()
          Returns the bounding box of the Line2D.
 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()
           
 Collection<? extends Line2D> getContinuousCurves()
          Returns the collection of continuous curves which constitute this curve.
 double getCurvature(double t)
          Returns 0 as every linear shape.
 double getDistance(double x, double y)
          Get the distance of the point (x, y) to this edge.
 double getDistance(Point2D p)
          Get the distance of the point (x, y) to this edge.
 Point2D getFirstPoint()
          Get the first point of the curve.
 GeneralPath getGeneralPath()
           
 double getHorizontalAngle()
          Gets Angle with axis (O,i), counted counter-clockwise.
 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.
 Point2D getLastPoint()
          Get the last point of the curve.
 double getLength()
           
 double getLength(double pos)
           
 Point2D getOrigin()
          Returns a point in the linear shape.
 Point2D getOtherPoint(Point2D point)
          Return the opposite vertex of the edge.
 Line2D getParallel(double d)
          Creates a new curve, formed by the points with parameterization: p(t) = c(t) + d*n(t)/|n(t)|, with p(t) being a point of the original curve, n(t) the normal of the curve, and |n| being the norm of n.
In the case of a continuous curve formed by several smooth circulinear elements, the parallels of contiguous elements are joined by a circle arc.
 StraightLine2D getParallel(Point2D point)
          Create a straight line parallel to this object, and going through the given point.
 double[][] getParametric()
           
 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 getPoint1()
          Return the first point of the edge.
 Point2D getPoint2()
          Return the last point of the edge.
 double[] getPolarCoefficients()
           
 double getPosition(double length)
           
 double getPosition(Point2D point)
          Gets position of the point on the line.
 Line2D getReverseCurve()
          Returns the line object which starts at point2 and ends at point1.
 double getSignedDistance(double x, double y)
          The same as getSignedDistance(Point2D), but by passing 2 double as arguments.
 double getSignedDistance(Point2D p)
          Get the signed distance of the curve to the given point: this distance is positive if the point lies outside the shape, and is negative if the point lies inside the shape.
 double[] getSignedPolarCoefficients()
           
 Collection<? extends Line2D> getSmoothPieces()
          Returns a set of smooth curves.
 Line2D getSubCurve(double t0, double t1)
          Return a new Line2D, which is the portion of the line delimited by parameters t0 and t1.
 StraightLine2D getSupportingLine()
           
 double getT0()
          Returns 0.
 double getT1()
          Returns 1.
 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.
 double getX1()
           
 double getX2()
           
 double getY1()
           
 double getY2()
           
static boolean intersects(Line2D line1, Line2D line2)
          Checks if two line intersect.
 boolean isBounded()
          Returns true
 boolean isClosed()
          Returns false.
 boolean isColinear(LinearShape2D line)
           
 boolean isEmpty()
          Returns false
 boolean isInside(Point2D point)
          Returns true if the point is 'inside' the domain bounded by the curve.
 boolean isParallel(LinearShape2D line)
          Test if the this object is parallel to the given one.
 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)
           
 String toString()
           
 Line2D transform(AffineTransform2D trans)
          Transforms the shape 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, wrapCurve
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface math.geom2d.curve.ContinuousCurve2D
getAsPolyline, getLeftTangent, getRightTangent
 
Methods inherited from interface math.geom2d.curve.Curve2D
draw, getAsAWTShape, getSingularPoints, isSingular
 

Field Detail

p1

public Point2D p1
The origin point.


p2

public Point2D p2
The destination point.

Constructor Detail

Line2D

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


Line2D

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

Method Detail

intersects

public static boolean intersects(Line2D line1,
                                 Line2D line2)
Checks if two line intersect. Uses the Point2D.ccw method, which is based on Sedgewick algorithm.

Parameters:
line1 - a Line2D object
line2 - a Line2D object
Returns:
true if the 2 lines intersect

create

public static Line2D create(Point2D p1,
                            Point2D p2)
Static factory for creating a new Line2D, starting from p1 and finishing at p2.

Since:
0.8.1

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

setPoint1

public void setPoint1(Point2D point)

setPoint2

public void setPoint2(Point2D point)

isColinear

public boolean isColinear(LinearShape2D line)

isParallel

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


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

getParallel

public Line2D getParallel(double d)
Description copied from interface: CirculinearCurve2D
Creates a new curve, formed by the points with parameterization: p(t) = c(t) + d*n(t)/|n(t)|, with p(t) being a point of the original curve, n(t) the normal of the curve, and |n| being the norm of n.
In the case of a continuous curve formed by several smooth circulinear elements, the parallels of contiguous elements are joined by a circle arc.

Specified by:
getParallel in interface CirculinearContinuousCurve2D
Specified by:
getParallel in interface CirculinearCurve2D
Specified by:
getParallel in interface CirculinearElement2D
Specified by:
getParallel in interface ContinuousCirculinearCurve2D
Parameters:
d - the distance between the original curve and he parallel curve.
Returns:
the parallel curve

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

getParametric

public double[][] getParametric()

getCartesianEquation

public double[] getCartesianEquation()

getPolarCoefficients

public double[] getPolarCoefficients()

getSignedPolarCoefficients

public double[] getSignedPolarCoefficients()

getHorizontalAngle

public double getHorizontalAngle()
Description copied from interface: LinearShape2D
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)
Description copied from interface: LinearShape2D
Returns the unique intersection with a linear shape. If the intersection doesn't exist (parallel lines), returns null.

Specified by:
getIntersection in interface LinearShape2D

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.

getSupportingLine

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

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

getSignedDistance

public double getSignedDistance(Point2D p)
Description copied from interface: OrientedCurve2D
Get the signed distance of the curve to the given point: this distance is positive if the point lies outside the shape, and is negative if the point lies inside the shape. In this case, absolute value of distance is equals to the distance to the border of the shape.

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)
Description copied from interface: OrientedCurve2D
The same as getSignedDistance(Point2D), but by passing 2 double as arguments.

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

getSmoothPieces

public Collection<? extends Line2D> getSmoothPieces()
Description copied from interface: ContinuousCurve2D
Returns a set of smooth curves.

Specified by:
getSmoothPieces in interface CirculinearContinuousCurve2D
Specified by:
getSmoothPieces in interface ContinuousCirculinearCurve2D
Specified by:
getSmoothPieces in interface ContinuousCurve2D
Overrides:
getSmoothPieces in class AbstractSmoothCurve2D

isClosed

public boolean isClosed()
Returns false.

Specified by:
isClosed in interface ContinuousCurve2D
See Also:
ContinuousCurve2D.isClosed()

getDistance

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

Specified by:
getDistance in interface Shape2D

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

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 point

clip

public CurveSet2D<? extends Line2D> 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.

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

getBoundingBox

public Box2D getBoundingBox()
Returns the bounding box of the Line2D.

Specified by:
getBoundingBox in interface Shape2D
Returns:
the bounding box of the shape.

getTangent

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

getCurvature

public double getCurvature(double t)
Returns 0 as every linear shape.

Specified by:
getCurvature in interface SmoothCurve2D

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

isInside

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

Specified by:
isInside in interface OrientedCurve2D
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 0.

Specified by:
getT0 in interface Curve2D

getT1

public double getT1()
Returns 1.

Specified by:
getT1 in interface Curve2D

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.

Specified by:
getPoint in interface Curve2D

getFirstPoint

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

Specified by:
getFirstPoint in interface Curve2D
Overrides:
getFirstPoint in class AbstractContinuousCurve2D
Returns:
the first point of the curve

getLastPoint

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

Specified by:
getLastPoint in interface Curve2D
Overrides:
getLastPoint in class AbstractContinuousCurve2D
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.

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

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

getReverseCurve

public Line2D getReverseCurve()
Returns the line object which starts at point2 and ends at point1.

Specified by:
getReverseCurve in interface CirculinearContinuousCurve2D
Specified by:
getReverseCurve in interface CirculinearCurve2D
Specified by:
getReverseCurve in interface CirculinearElement2D
Specified by:
getReverseCurve in interface ContinuousCirculinearCurve2D
Specified by:
getReverseCurve in interface ContinuousCurve2D
Specified by:
getReverseCurve in interface Curve2D
Specified by:
getReverseCurve in interface SmoothCurve2D
Specified by:
getReverseCurve in interface ContinuousOrientedCurve2D
Specified by:
getReverseCurve in interface OrientedCurve2D
Specified by:
getReverseCurve in interface SmoothOrientedCurve2D

getContinuousCurves

public Collection<? extends Line2D> 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.

getSubCurve

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

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.

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

transform

public Line2D transform(AffineTransform2D trans)
Description copied from interface: Shape2D
Transforms the shape by an affine transform. Subclasses may override the type of returned shape.

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:
trans - an affine transform
Returns:
the transformed shape

contains

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

Specified by:
contains in interface Shape2D

contains

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

Specified by:
contains in interface Shape2D

isBounded

public boolean isBounded()
Returns true

Specified by:
isBounded in interface Shape2D

isEmpty

public boolean isEmpty()
Returns false

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

getGeneralPath

public GeneralPath getGeneralPath()

appendPath

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

Specified by:
appendPath in interface ContinuousCurve2D
Parameters:
path - a path to modify
Returns:
the modified path

toString

public String toString()
Overrides:
toString in class Object

equals

public boolean equals(Object obj)
Two Line2D are equals if the share the two same points, in the same order.

Overrides:
equals in class Object
Parameters:
obj - the edge to compare to.
Returns:
true if extremities of both edges are the same.

clone

public Line2D clone()
Description copied from interface: Curve2D
Overrides Object declaration to ensure Curve2D implementation are cloned as Curve2D.

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


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