math.geom2d.line
Class 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:
java.lang.Cloneable, CirculinearContinuousCurve2D, CirculinearCurve2D, CirculinearElement2D, CirculinearShape2D, ContinuousCurve2D, Curve2D, SmoothCurve2D, ContinuousOrientedCurve2D, OrientedCurve2D, SmoothOrientedCurve2D, GeometricObject2D, LinearElement2D, LinearShape2D, Shape2D

public class LineSegment2D
extends AbstractLine2D
implements java.lang.Cloneable, CirculinearElement2D

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


Field Summary
 
Fields inherited from interface math.geom2d.Shape2D
ACCURACY
 
Constructor Summary
LineSegment2D(double x1, double y1, double x2, double y2)
          Defines a new Edge with two extremities.
LineSegment2D(Point2D point1, Point2D point2)
          Defines a new Edge with two extremities.
 
Method Summary
 boolean almostEquals(GeometricObject2D obj, double eps)
          Checks if the two objects are similar up to a given threshold value.
 java.awt.geom.GeneralPath appendPath(java.awt.geom.GeneralPath path)
          Appends a line to the current path.
 Box2D boundingBox()
          Returns the bounding box of this line segment.
 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)
          Deprecated. since 0.11.1
 double distance(double x, double y)
          Get the distance of the point (x, y) to this edge.
 boolean equals(java.lang.Object obj)
           
 Point2D firstPoint()
          Returns the first point of the edge.
static double getEdgeAngle(LineSegment2D edge1, LineSegment2D edge2)
          Returns angle between two edges sharing one vertex.
 java.awt.geom.GeneralPath getGeneralPath()
          deprecated
 StraightLine2D getMedian()
          Returns the median of the edge, that is the locus of points located at equal distance of each vertex.
static StraightLine2D getMedian(LineSegment2D edge)
          Returns the straight line that is the median of the edge extremities.
 double getT0()
          Deprecated. replaced by t0() (since 0.11.1).
 double getT1()
          Deprecated. replaced by t1() (since 0.11.1).
static boolean intersects(LineSegment2D edge1, LineSegment2D edge2)
          Checks if two line segment intersect.
 boolean isBounded()
          Returns true
 Point2D lastPoint()
          Returns the last point of the edge.
 double length()
          Returns the length of the line segment.
 Point2D opposite(Point2D point)
          Returns the opposite vertex of the edge.
 LineSegment2D parallel(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.
 Point2D point(double t)
          Returns the point located at the given position on the curve.
 LineSegment2D reverse()
          Returns the LineSegment which start from last point of this line segment, and which ends at the fist point of this last segment.
 double signedDistance(double x, double y)
          Returns the signed distance of the StraightObject2d to the given point.
 double t0()
          Returns the parameter of the first point of the edge, equals to 0.
 double t1()
          Returns the parameter of the last point of the edge, equals to 1.
 java.lang.String toString()
           
 LineSegment2D transform(AffineTransform2D trans)
          Transforms the curve by an affine transform.
 
Methods inherited from class math.geom2d.line.AbstractLine2D
buffer, cartesianEquation, clip, contains, continuousCurves, curvature, direction, distance, getIntersection, getSymmetric, getSymmetric, horizontalAngle, intersection, intersections, isClosed, isColinear, isColinear, isEmpty, isInside, isParallel, isParallel, length, origin, parallel, parametric, perpendicular, polarCoefficients, polarCoefficientsSigned, position, position, positionOnLine, positionOnLine, project, projectedPoint, projectedPoint, signedDistance, smoothPieces, subCurve, supportingLine, tangent, transform, windingAngle
 
Methods inherited from class math.geom2d.curve.AbstractSmoothCurve2D
isSingular, leftTangent, normal, rightTangent, singularPoints, vertices
 
Methods inherited from class math.geom2d.curve.AbstractContinuousCurve2D
asAwtShape, asPolyline, draw
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface math.geom2d.circulinear.CirculinearElement2D
clip, subCurve, transform
 
Methods inherited from interface math.geom2d.circulinear.CirculinearContinuousCurve2D
smoothPieces
 
Methods inherited from interface math.geom2d.circulinear.CirculinearCurve2D
continuousCurves, length, position
 
Methods inherited from interface math.geom2d.circulinear.CirculinearShape2D
buffer
 
Methods inherited from interface math.geom2d.curve.SmoothCurve2D
normal, tangent
 
Methods inherited from interface math.geom2d.curve.ContinuousCurve2D
asPolyline, curvature, isClosed, leftTangent, rightTangent
 
Methods inherited from interface math.geom2d.domain.OrientedCurve2D
isInside, signedDistance, windingAngle
 
Methods inherited from interface math.geom2d.curve.Curve2D
asAwtShape, draw, intersections, isSingular, position, project, singularPoints, vertices
 
Methods inherited from interface math.geom2d.Shape2D
contains, distance, isEmpty
 

Constructor Detail

LineSegment2D

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


LineSegment2D

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

Method Detail

create

@Deprecated
public static LineSegment2D create(Point2D p1,
                                              Point2D p2)
Deprecated. since 0.11.1

Static factory for creating a new line segment between two points.


getMedian

public static StraightLine2D getMedian(LineSegment2D edge)
Returns the straight line that is the median of the edge extremities.


getEdgeAngle

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


intersects

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

opposite

public Point2D opposite(Point2D point)
Returns 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()
Returns the median of the edge, that is the locus of points located at equal distance of each vertex.


length

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

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

parallel

public LineSegment2D parallel(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:
parallel in interface CirculinearContinuousCurve2D
Specified by:
parallel in interface CirculinearCurve2D
Specified by:
parallel in interface CirculinearElement2D
Parameters:
d - the distance between the original curve and he parallel curve.
Returns:
the parallel curve

signedDistance

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

firstPoint

public Point2D firstPoint()
Returns the first point of the edge.

Specified by:
firstPoint in interface Curve2D
Overrides:
firstPoint in class AbstractContinuousCurve2D
Returns:
the first point of the edge
See Also:
Curve2D.t0(), Curve2D.point(double)

lastPoint

public Point2D lastPoint()
Returns the last point of the edge.

Specified by:
lastPoint in interface Curve2D
Overrides:
lastPoint in class AbstractContinuousCurve2D
Returns:
the last point of the edge
See Also:
Curve2D.t1(), Curve2D.point(double)

t0

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

Specified by:
t0 in interface Curve2D

getT0

@Deprecated
public double getT0()
Deprecated. replaced by t0() (since 0.11.1).

Specified by:
getT0 in interface Curve2D

t1

public double t1()
Returns the parameter of the last point of the edge, equals to 1.

Specified by:
t1 in interface Curve2D

getT1

@Deprecated
public double getT1()
Deprecated. replaced by t1() (since 0.11.1).

Specified by:
getT1 in interface Curve2D

point

public Point2D point(double t)
Description copied from interface: Curve2D
Returns the point located at the given position on 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:
point in interface Curve2D

reverse

public LineSegment2D reverse()
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:
reverse in interface CirculinearContinuousCurve2D
Specified by:
reverse in interface CirculinearCurve2D
Specified by:
reverse in interface CirculinearElement2D
Specified by:
reverse in interface ContinuousCurve2D
Specified by:
reverse in interface Curve2D
Specified by:
reverse in interface SmoothCurve2D
Specified by:
reverse in interface ContinuousOrientedCurve2D
Specified by:
reverse in interface OrientedCurve2D
Specified by:
reverse 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

distance

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

Specified by:
distance in interface Shape2D
Overrides:
distance in class AbstractLine2D
Parameters:
x - the x-coordinate of the point
y - the 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 LinearElement2D
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

boundingBox

public Box2D boundingBox()
Returns the bounding box of this line segment.

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

appendPath

public java.awt.geom.GeneralPath appendPath(java.awt.geom.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 java.awt.geom.GeneralPath getGeneralPath()
deprecated


almostEquals

public boolean almostEquals(GeometricObject2D obj,
                            double eps)
Description copied from interface: GeometricObject2D
Checks if the two objects are similar up to a given threshold value. This method can be used to compare the results of geometric computations, that introduce errors due to numerical computations.

Specified by:
almostEquals in interface GeometricObject2D
Parameters:
obj - the object to compare
eps - a threshold value, for example the minimal coordinate difference
Returns:
true if both object have the same value up to the threshold

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.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