public class Line2D extends AbstractSmoothCurve2D implements LinearShape2D, CirculinearElement2D, Cloneable
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.
| Modifier and Type | Field and Description |
|---|---|
Point2D |
p1
The origin point.
|
Point2D |
p2
The destination point.
|
| Constructor and Description |
|---|
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.
|
| Modifier and Type | Method and Description |
|---|---|
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.
|
getLeftTangent, getRightTangent, getSingularPoints, isSingulardraw, getAsAWTShape, getAsPolyline, wrapCurvefinalize, getClass, hashCode, notify, notifyAll, wait, wait, waitgetAsPolyline, getLeftTangent, getRightTangentdraw, getAsAWTShape, getSingularPoints, isSingularpublic Line2D(double x1,
double y1,
double x2,
double y2)
public static boolean intersects(Line2D line1, Line2D line2)
Point2D.ccw
method, which is based on Sedgewick algorithm.line1 - a Line2D objectline2 - a Line2D objectpublic static Line2D create(Point2D p1, Point2D p2)
public Point2D getPoint1()
public Point2D getPoint2()
public double getX1()
public double getY1()
public double getX2()
public double getY2()
public Point2D getOtherPoint(Point2D point)
point - : one of the vertices of the edgepublic void setPoint1(Point2D point)
public void setPoint2(Point2D point)
public boolean isColinear(LinearShape2D line)
public boolean isParallel(LinearShape2D line)
public CirculinearDomain2D getBuffer(double dist)
CirculinearShape2DgetBuffer in interface CirculinearShape2Ddist - the maximal distance between a point of the buffer and the
shapepublic Line2D getParallel(double d)
CirculinearCurve2D 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.getParallel in interface CirculinearContinuousCurve2DgetParallel in interface CirculinearCurve2DgetParallel in interface CirculinearElement2DgetParallel in interface ContinuousCirculinearCurve2Dd - the distance between the original curve and he parallel curve.public double getLength()
getLength in interface CirculinearCurve2Dpublic double getLength(double pos)
getLength in interface CirculinearCurve2Dpublic double getPosition(double length)
getPosition in interface CirculinearCurve2Dpublic CirculinearElement2D transform(CircleInversion2D inv)
CirculinearShape2Dtransform in interface CirculinearContinuousCurve2Dtransform in interface CirculinearCurve2Dtransform in interface CirculinearElement2Dtransform in interface CirculinearShape2Dtransform in interface ContinuousCirculinearCurve2Dinv - the circle inversionpublic double[][] getParametric()
public double[] getCartesianEquation()
public double[] getPolarCoefficients()
public double[] getSignedPolarCoefficients()
public double getHorizontalAngle()
LinearShape2DgetHorizontalAngle in interface LinearShape2Dpublic Point2D getIntersection(LinearShape2D line)
LinearShape2DgetIntersection in interface LinearShape2Dpublic Point2D getOrigin()
LinearShape2DgetOrigin in interface LinearShape2Dpublic StraightLine2D getSupportingLine()
getSupportingLine in interface LinearShape2Dpublic Vector2D getVector()
LinearShape2DgetVector in interface LinearShape2Dpublic double getSignedDistance(Point2D p)
OrientedCurve2DgetSignedDistance in interface OrientedCurve2Dp - a point of the planepublic double getSignedDistance(double x,
double y)
OrientedCurve2DgetSignedDistance in interface OrientedCurve2Dx - x-coord of a pointy - y-coord of a pointpublic Collection<? extends Line2D> getSmoothPieces()
ContinuousCurve2DgetSmoothPieces in interface CirculinearContinuousCurve2DgetSmoothPieces in interface ContinuousCirculinearCurve2DgetSmoothPieces in interface ContinuousCurve2DgetSmoothPieces in class AbstractSmoothCurve2Dpublic boolean isClosed()
isClosed in interface ContinuousCurve2DContinuousCurve2D.isClosed()public double getDistance(Point2D p)
getDistance in interface Shape2Dpublic double getDistance(double x,
double y)
getDistance in interface Shape2Dpublic StraightLine2D getParallel(Point2D point)
point - the point to go throughpublic StraightLine2D getPerpendicular(Point2D point)
point - : the point to go throughpublic CurveSet2D<? extends Line2D> clip(Box2D box)
clip in interface CirculinearContinuousCurve2Dclip in interface CirculinearCurve2Dclip in interface CirculinearElement2Dclip in interface ContinuousCirculinearCurve2Dclip in interface ContinuousCurve2Dclip in interface Curve2Dclip in interface SmoothCurve2Dclip in interface ContinuousOrientedCurve2Dclip in interface OrientedCurve2Dclip in interface SmoothOrientedCurve2Dclip in interface Shape2Dbox - the clipping boxpublic Box2D getBoundingBox()
getBoundingBox in interface Shape2Dpublic Vector2D getTangent(double t)
getTangent in interface SmoothCurve2Dpublic double getCurvature(double t)
getCurvature in interface SmoothCurve2Dpublic double getWindingAngle(Point2D point)
OrientedCurve2DgetWindingAngle in interface OrientedCurve2Dpoint - a point of the planepublic boolean isInside(Point2D point)
OrientedCurve2DisInside in interface OrientedCurve2Dpoint - a point in the planepublic Point2D getPoint(double t)
Curve2Dpublic Point2D getFirstPoint()
getFirstPoint in interface Curve2DgetFirstPoint in class AbstractContinuousCurve2Dpublic Point2D getLastPoint()
getLastPoint in interface Curve2DgetLastPoint in class AbstractContinuousCurve2Dpublic double getPosition(Point2D point)
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. t = (xp - x0)/dx <\code>, or equivalently : t = (yp - y0)/dy <\code>.
getPosition in interface Curve2Dpoint - a point belonging to the curvepublic double project(Point2D point)
Curve2Dpublic Line2D getReverseCurve()
point2 and ends at
point1.getReverseCurve in interface CirculinearContinuousCurve2DgetReverseCurve in interface CirculinearCurve2DgetReverseCurve in interface CirculinearElement2DgetReverseCurve in interface ContinuousCirculinearCurve2DgetReverseCurve in interface ContinuousCurve2DgetReverseCurve in interface Curve2DgetReverseCurve in interface SmoothCurve2DgetReverseCurve in interface ContinuousOrientedCurve2DgetReverseCurve in interface OrientedCurve2DgetReverseCurve in interface SmoothOrientedCurve2Dpublic Collection<? extends Line2D> getContinuousCurves()
Curve2DgetContinuousCurves in interface CirculinearCurve2DgetContinuousCurves in interface Curve2DgetContinuousCurves in class AbstractContinuousCurve2Dpublic Line2D getSubCurve(double t0, double t1)
getSubCurve in interface CirculinearContinuousCurve2DgetSubCurve in interface CirculinearCurve2DgetSubCurve in interface CirculinearElement2DgetSubCurve in interface ContinuousCirculinearCurve2DgetSubCurve in interface ContinuousCurve2DgetSubCurve in interface Curve2DgetSubCurve in interface SmoothCurve2DgetSubCurve in interface ContinuousOrientedCurve2DgetSubCurve in interface SmoothOrientedCurve2Dt0 - position of the start of the sub-curvet1 - position of the end of the sub-curvepublic Collection<Point2D> getIntersections(LinearShape2D line)
Curve2DgetIntersections in interface Curve2Dpublic Line2D transform(AffineTransform2D trans)
Shape2Dtransform in interface ContinuousCurve2Dtransform in interface Curve2Dtransform in interface SmoothCurve2Dtransform in interface ContinuousOrientedCurve2Dtransform in interface OrientedCurve2Dtransform in interface SmoothOrientedCurve2Dtransform in interface LinearShape2Dtransform in interface Shape2Dtrans - an affine transformpublic boolean contains(double x,
double y)
public boolean contains(Point2D p)
public boolean isEmpty()
public GeneralPath getGeneralPath()
public GeneralPath appendPath(GeneralPath path)
ContinuousCurve2DappendPath in interface ContinuousCurve2Dpath - a path to modifypublic boolean equals(Object obj)
Copyright © 2012 AMIS research group, Faculty of Mathematics and Physics, Charles University in Prague, Czech Republic. All Rights Reserved.