math.geom2d.line
Class LineSegment2D
- java.lang.Object
-
- math.geom2d.curve.AbstractContinuousCurve2D
-
- math.geom2d.curve.AbstractSmoothCurve2D
-
- math.geom2d.line.AbstractLine2D
-
- 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.
-
-
Constructor Summary
Constructors Constructor and Description 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
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method and Description booleanalmostEquals(GeometricObject2D obj, double eps)Checks if the two objects are similar up to a given threshold value.java.awt.geom.GeneralPathappendPath(java.awt.geom.GeneralPath path)Appends a line to the current path.Box2DboundingBox()Returns the bounding box of this line segment.LineSegment2Dclone()Deprecated.use copy constructor instead (0.11.2)booleancontains(double xp, double yp)Checks if the shape contains the planar point defined by (x,y).static LineSegment2Dcreate(Point2D p1, Point2D p2)Deprecated.since 0.11.1doubledistance(double x, double y)Get the distance of the point (x, y) to this edge.booleanequals(java.lang.Object obj)Point2DfirstPoint()Returns the first point of the edge.static doublegetEdgeAngle(LineSegment2D edge1, LineSegment2D edge2)Returns angle between two edges sharing one vertex.java.awt.geom.GeneralPathgetGeneralPath()deprecatedStraightLine2DgetMedian()Returns the median of the edge, that is the locus of points located at equal distance of each vertex.static StraightLine2DgetMedian(LineSegment2D edge)Returns the straight line that is the median of the edge extremities.doublegetT0()Deprecated.replaced by t0() (since 0.11.1).doublegetT1()Deprecated.replaced by t1() (since 0.11.1).static booleanintersects(LineSegment2D edge1, LineSegment2D edge2)Checks if two line segment intersect.booleanisBounded()Returns truePoint2DlastPoint()Returns the last point of the edge.doublelength()Returns the length of the line segment.Point2Dopposite(Point2D point)Returns the opposite vertex of the edge.LineSegment2Dparallel(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.Point2Dpoint(double t)Returns the point located at the given position on the curve.LineSegment2Dreverse()Returns the LineSegment which start from last point of this line segment, and which ends at the fist point of this last segment.doublesignedDistance(double x, double y)Returns the signed distance of the StraightObject2d to the given point.doublet0()Returns the parameter of the first point of the edge, equals to 0.doublet1()Returns the parameter of the last point of the edge, equals to 1.java.lang.StringtoString()LineSegment2Dtransform(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
-
-
-
-
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.1Static 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 segmentedge2- 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:
lengthin interfaceCirculinearCurve2D- Overrides:
lengthin classAbstractLine2D- Returns:
- the length of the curve
-
parallel
public LineSegment2D parallel(double d)
Description copied from interface:CirculinearCurve2DCreates 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:
parallelin interfaceCirculinearContinuousCurve2D- Specified by:
parallelin interfaceCirculinearCurve2D- Specified by:
parallelin interfaceCirculinearElement2D- 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:AbstractLine2DReturns 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:
signedDistancein interfaceOrientedCurve2D- Overrides:
signedDistancein classAbstractLine2D- Parameters:
x- x-coord of a pointy- 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:
firstPointin interfaceCurve2D- Overrides:
firstPointin classAbstractContinuousCurve2D- 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:
lastPointin interfaceCurve2D- Overrides:
lastPointin classAbstractContinuousCurve2D- 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.
-
getT0
@Deprecated public double getT0()
Deprecated. replaced by t0() (since 0.11.1).
-
t1
public double t1()
Returns the parameter of the last point of the edge, equals to 1.
-
getT1
@Deprecated public double getT1()
Deprecated. replaced by t1() (since 0.11.1).
-
point
public Point2D point(double t)
Description copied from interface:Curve2DReturns 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.
-
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:
reversein interfaceCirculinearContinuousCurve2D- Specified by:
reversein interfaceCirculinearCurve2D- Specified by:
reversein interfaceCirculinearElement2D- Specified by:
reversein interfaceContinuousCurve2D- Specified by:
reversein interfaceCurve2D- Specified by:
reversein interfaceSmoothCurve2D- Specified by:
reversein interfaceContinuousOrientedCurve2D- Specified by:
reversein interfaceOrientedCurve2D- Specified by:
reversein interfaceSmoothOrientedCurve2D
-
contains
public boolean contains(double xp, double yp)Description copied from interface:Shape2DChecks if the shape contains the planar point defined by (x,y).
-
distance
public double distance(double x, double y)Get the distance of the point (x, y) to this edge.- Specified by:
distancein interfaceShape2D- Overrides:
distancein classAbstractLine2D- Parameters:
x- the x-coordinate of the pointy- 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:Curve2DTransforms the curve by an affine transform. The result is an instance of Curve2D.- Specified by:
transformin interfaceContinuousCurve2D- Specified by:
transformin interfaceCurve2D- Specified by:
transformin interfaceSmoothCurve2D- Specified by:
transformin interfaceContinuousOrientedCurve2D- Specified by:
transformin interfaceOrientedCurve2D- Specified by:
transformin interfaceSmoothOrientedCurve2D- Specified by:
transformin interfaceLinearElement2D- Specified by:
transformin interfaceLinearShape2D- Specified by:
transformin interfaceShape2D- Specified by:
transformin classAbstractLine2D- Parameters:
trans- an affine transform- Returns:
- the transformed shape
-
boundingBox
public Box2D boundingBox()
Returns the bounding box of this line segment.- Specified by:
boundingBoxin interfaceShape2D- 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:
appendPathin interfaceContinuousCurve2D- 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:GeometricObject2DChecks 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:
almostEqualsin interfaceGeometricObject2D- Parameters:
obj- the object to compareeps- 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:
toStringin classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
clone
@Deprecated public LineSegment2D clone()
Deprecated. use copy constructor instead (0.11.2)- Specified by:
clonein interfaceCurve2D- Specified by:
clonein classAbstractLine2D
-
-
DMelt 3.0 © DataMelt by jWork.ORG