math.geom2d.line
Class LineSegment2D

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

public class LineSegment2D
extends AbstractLine2D
implements Cloneable, CirculinearElement2D

Line segment, defined as the set of points located between the two end points.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class math.geom2d.line.AbstractLine2D
dx, dy, x0, y0
 
Fields inherited from interface math.geom2d.Shape2D
ACCURACY
 
Constructor Summary
LineSegment2D(double x1, double y1, double x2, double y2)
          Define a new Edge with two extremities.
LineSegment2D(Point2D point1, Point2D point2)
          Define a new Edge with two extremities.
 
Method Summary
 GeneralPath appendPath(GeneralPath path)
          Appends a line to the current path.
 LineSegment2D clone()
          Ensures public declaration of clone(), and ensures valid return type.
 boolean contains(double xp, double yp)
          Checks if the shape contains the planar point defined by (x,y).
static LineSegment2D create(Point2D p1, Point2D p2)
          Static factory for creating a new line segment between two points.
 boolean equals(Object obj)
           
 Box2D getBoundingBox()
          Returns the bounding box of the shape.
 double getDistance(double x, double y)
          Get the distance of the point (x, y) to this edge.
static double getEdgeAngle(LineSegment2D edge1, LineSegment2D edge2)
          Returns angle between two edges sharing one vertex.
 Point2D getFirstPoint()
          Return the first point of the edge.
 GeneralPath getGeneralPath()
          deprecated
 Point2D getLastPoint()
          Return the last point of the edge.
 double getLength()
          Returns the length of the line segment.
 StraightLine2D getMedian()
          Return the median of the edge, that is the locus of points located at equal distance of each vertex.
static StraightLine2D getMedian(LineSegment2D edge)
           
 Point2D getOtherPoint(Point2D point)
          Return the opposite vertex of the edge.
 LineSegment2D 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.
 Point2D getPoint(double t)
          Gets the point from a parametric representation of the curve.
 LineSegment2D getReverseCurve()
          Returns the LineSegment which start from last point of this line segment, and which ends at the fist point of this last segment.
 double getSignedDistance(double x, double y)
          Get the signed distance of the StraightObject2d to the given point.
 double getT0()
          Returns the parameter of the first point of the edge, equals to 0.
 double getT1()
          Returns the parameter of the last point of the edge, equals to 1.
static boolean intersects(LineSegment2D edge1, LineSegment2D edge2)
          Checks if two line segment intersect.
 boolean isBounded()
          Returns true
 void setLineSegment(double x1, double y1, double x2, double y2)
          Deprecated. lines will become immutable in a future release
 void setLineSegment(Point2D p1, Point2D p2)
          Deprecated. lines will become immutable in a future release
 String toString()
           
 LineSegment2D transform(AffineTransform2D trans)
          Transforms the curve by an affine transform.
 
Methods inherited from class math.geom2d.line.AbstractLine2D
clip, contains, getBuffer, getCartesianEquation, getContinuousCurves, getCurvature, getDistance, getHorizontalAngle, getIntersection, getIntersection, getIntersections, getLength, getOrigin, getParallel, getParametric, getPerpendicular, getPolarCoefficients, getPosition, getPosition, getPositionOnLine, getPositionOnLine, getProjectedPoint, getProjectedPoint, getSignedDistance, getSignedPolarCoefficients, getSmoothPieces, getSubCurve, getSupportingLine, getSymmetric, getSymmetric, getTangent, getVector, getWindingAngle, isClosed, isColinear, isColinear, isEmpty, isInside, isParallel, isParallel, project, supportContains, transform
 
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.circulinear.CirculinearElement2D
clip, getSubCurve, transform
 
Methods inherited from interface math.geom2d.circulinear.CirculinearContinuousCurve2D
getSmoothPieces
 
Methods inherited from interface math.geom2d.circulinear.CirculinearCurve2D
getContinuousCurves, getLength, getPosition
 
Methods inherited from interface math.geom2d.circulinear.CirculinearShape2D
getBuffer
 
Methods inherited from interface math.geom2d.curve.ContinuousCurve2D
getAsPolyline, getLeftTangent, getRightTangent, isClosed
 
Methods inherited from interface math.geom2d.domain.OrientedCurve2D
getSignedDistance, getWindingAngle, isInside
 
Methods inherited from interface math.geom2d.curve.Curve2D
draw, getAsAWTShape, getIntersections, getPosition, getSingularPoints, isSingular, project
 
Methods inherited from interface math.geom2d.Shape2D
contains, getDistance, isEmpty
 
Methods inherited from interface math.geom2d.curve.SmoothCurve2D
getCurvature, getTangent
 

Constructor Detail

LineSegment2D

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


LineSegment2D

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

Method Detail

create

public static final LineSegment2D create(Point2D p1,
                                         Point2D p2)
Static factory for creating a new line segment between two points.

Since:
0.8.1

getMedian

public static final StraightLine2D getMedian(LineSegment2D edge)

getEdgeAngle

public static final double getEdgeAngle(LineSegment2D edge1,
                                        LineSegment2D edge2)
Returns angle between two edges sharing one vertex.


intersects

public static final boolean intersects(LineSegment2D edge1,
                                       LineSegment2D edge2)
Checks if two line segment intersect. Uses the Point2D.ccw() method, which is based on Sedgewick algorithm.

Parameters:
edge1 - a line segment
edge2 - a line segment
Returns:
true if the 2 line segments intersect

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, or null if point is nor a vertex of the edge

getMedian

public StraightLine2D getMedian()
Return the median of the edge, that is the locus of points located at equal distance of each vertex.


setLineSegment

@Deprecated
public void setLineSegment(Point2D p1,
                                      Point2D p2)
Deprecated. lines will become immutable in a future release


setLineSegment

@Deprecated
public void setLineSegment(double x1,
                                      double y1,
                                      double x2,
                                      double y2)
Deprecated. lines will become immutable in a future release


getLength

public double getLength()
Returns the length of the line segment.

Specified by:
getLength in interface CirculinearCurve2D
Overrides:
getLength in class AbstractLine2D
Returns:
the length of the curve

getParallel

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

getSignedDistance

public double getSignedDistance(double x,
                                double y)
Description copied from class: AbstractLine2D
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
Overrides:
getSignedDistance in class AbstractLine2D
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

getFirstPoint

public Point2D getFirstPoint()
Return the first point of the edge.

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

getLastPoint

public Point2D getLastPoint()
Return the last point of the edge.

Specified by:
getLastPoint in interface Curve2D
Overrides:
getLastPoint in class AbstractContinuousCurve2D
Returns:
the last point of the edge

getT0

public double getT0()
Returns the parameter of the first point of the edge, equals to 0.

Specified by:
getT0 in interface Curve2D

getT1

public double getT1()
Returns the parameter of the last point of the edge, equals to 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

getReverseCurve

public LineSegment2D getReverseCurve()
Returns the LineSegment which start from last point of this line segment, and which ends at the fist point of this last segment.

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

isBounded

public boolean isBounded()
Returns true

Specified by:
isBounded in interface Shape2D

contains

public boolean contains(double xp,
                        double yp)
Description copied from interface: Shape2D
Checks if the shape contains the planar point defined by (x,y).

Specified by:
contains 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
Overrides:
getDistance in class AbstractLine2D
Parameters:
x - x-coordinate of the point
y - y-coordinate of the point
Returns:
distance between this object and the point (x,y)

transform

public LineSegment2D 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 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
Specified by:
transform in class AbstractLine2D
Parameters:
trans - an affine transform
Returns:
the transformed shape

getBoundingBox

public Box2D getBoundingBox()
Description copied from interface: Shape2D
Returns the bounding box of the shape.

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

appendPath

public GeneralPath appendPath(GeneralPath path)
Appends a line to the current path.

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

getGeneralPath

public GeneralPath getGeneralPath()
deprecated


toString

public String toString()
Overrides:
toString in class Object

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

clone

public LineSegment2D clone()
Description copied from class: AbstractLine2D
Ensures public declaration of clone(), and ensures valid return type.

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


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