Class LineIntersector
- Namespace
- NetTopologySuite.Algorithm
- Assembly
- NetTopologySuite.dll
A LineIntersector
is an algorithm that can both test whether
two line segments intersect and compute the intersection point(s)
if they do.
There are three possible outcomes when determining whether two line segments intersect:
- NoIntersection - the segments do not intersect
- PointIntersection - the segments intersect in a single point
- CollinearIntersection - the segments are collinear and they intersect in a line segment
For segments which intersect in a single point, the point may be either an endpoint or in the interior of each segment. If the point lies in the interior of both segments, this is termed a proper intersection. The property IsProper test for this situation.
The intersection point(s) may be computed in a precise or non-precise manner. Computing an intersection point precisely involves rounding it via a supplied PrecisionModel.
LineIntersectors do not perform an initial envelope intersection test to determine if the segments are disjoint. This is because this class is likely to be used in a context where envelope overlap is already known to occur (or be likely).
public abstract class LineIntersector
- Inheritance
-
LineIntersector
- Derived
- Inherited Members
Constructors
LineIntersector()
Creates an instance of this class
protected LineIntersector()
Fields
CollinearIntersection
Indicates that line segments intersect in a line segment
public const int CollinearIntersection = 2
Field Value
InputLines
Array of coordinate arrays forming the lines
protected Coordinate[][] InputLines
Field Value
- Coordinate[][]
IntersectionLineIndex
The indexes of the endpoints of the intersection lines, in order along the corresponding line
protected int[] IntersectionLineIndex
Field Value
- int[]
IntersectionPoint
Array of
protected Coordinate[] IntersectionPoint
Field Value
NoIntersection
Indicates that line segments do not intersect
public const int NoIntersection = 0
Field Value
PointIntersection
Indicates that line segments intersect in a single point
public const int PointIntersection = 1
Field Value
Result
A value indicating the intersection result
Possible values are:protected int Result
Field Value
Properties
HasIntersection
Tests whether the input geometries intersect.
public bool HasIntersection { get; }
Property Value
- bool
true
if the input geometries intersect.
IntersectionNum
Returns the number of intersection points found. This will be either 0, 1 or 2.
public int IntersectionNum { get; }
Property Value
- int
The number of intersection points found (0, 1, or 2)
IsCollinear
Gets a value indicating if the computed intersection is collinear
protected bool IsCollinear { get; }
Property Value
IsEndPoint
Gets a value indicating if the intersection is an end-point intersection
protected bool IsEndPoint { get; }
Property Value
IsProper
Tests whether an intersection is proper. The intersection between two line segments is considered proper if they intersect in a single point in the interior of both segments (e.g. the intersection is a single point and is not equal to any of the endpoints). The intersection between a point and a line segment is considered proper if the point lies in the interior of the segment (e.g. is not equal to either of the endpoints).
public bool IsProper { get; protected set; }
Property Value
- bool
true
if the intersection is proper.
Pa
Alias the IntersectionPoint[0] for ease of reference
protected Coordinate Pa { get; }
Property Value
Pb
Alias the IntersectionPoint[1] for ease of reference
protected Coordinate Pb { get; }
Property Value
PrecisionModel
Force computed intersection to be rounded to a given precision model. No getter is provided, because the precision model is not required to be specified.
public PrecisionModel PrecisionModel { get; set; }
Property Value
Methods
ComputeEdgeDistance(Coordinate, Coordinate, Coordinate)
Computes the "edge distance" of an intersection point p along a segment. The edge distance is a metric of the point along the edge. The metric used is a robust and easy to compute metric function. It is not equivalent to the usual Euclidean metric. It relies on the fact that either the x or the y ordinates of the points in the edge are unique, depending on whether the edge is longer in the horizontal or vertical direction. NOTE: This function may produce incorrect distances for inputs where p is not precisely on p1-p2 (E.g. p = (139,9) p1 = (139,10), p2 = (280,1) produces distance 0.0, which is incorrect. My hypothesis is that the function is safe to use for points which are the result of rounding points which lie on the line, but not safe to use for truncated points.
public static double ComputeEdgeDistance(Coordinate p, Coordinate p0, Coordinate p1)
Parameters
p
Coordinatep0
Coordinatep1
Coordinate
Returns
ComputeIntLineIndex()
Computes the IntersectionLineIndex values.
protected void ComputeIntLineIndex()
ComputeIntLineIndex(int)
Computes the intersection line index
protected void ComputeIntLineIndex(int segmentIndex)
Parameters
segmentIndex
intThe segment index
ComputeIntersect(Coordinate, Coordinate, Coordinate, Coordinate)
Computes the intersection of two line segments, one defined by p1
and p2
,
the other by q1
and q2
.
public abstract int ComputeIntersect(Coordinate p1, Coordinate p2, Coordinate q1, Coordinate q2)
Parameters
p1
CoordinateThe 1st point of the 1st segment
p2
CoordinateThe 2nd point of the 1st segment
q1
CoordinateThe 1st point of the 2nd segment
q2
CoordinateThe 2nd point of the 2nd segment
Returns
Remarks
Don't use this function directly, it is not meant for public use. Please call ComputeIntersection(Coordinate, Coordinate, Coordinate, Coordinate) and test HasIntersection or IsCollinear along with IsProper and IsEndPoint.
ComputeIntersection(Coordinate, Coordinate, Coordinate)
Compute the intersection of a point p and the line p1-p2.
This function computes the bool value of the hasIntersection test.
The actual value of the intersection (if there is one)
is equal to the value of p
.
public abstract void ComputeIntersection(Coordinate p, Coordinate p1, Coordinate p2)
Parameters
p
Coordinatep1
Coordinatep2
Coordinate
ComputeIntersection(Coordinate, Coordinate, Coordinate, Coordinate)
Computes the intersection of the lines p1-p2 and p3-p4. This function computes both the bool value of the hasIntersection test and the (approximate) value of the intersection point itself (if there is one).
public void ComputeIntersection(Coordinate p1, Coordinate p2, Coordinate p3, Coordinate p4)
Parameters
p1
CoordinateThe 1st point of the 1st segment
p2
CoordinateThe 2nd point of the 1st segment
p3
CoordinateThe 1st point of the 2nd segment
p4
CoordinateThe 2nd point of the 2nd segment
GetEdgeDistance(int, int)
Computes the "edge distance" of an intersection point along the specified input line segment.
public double GetEdgeDistance(int segmentIndex, int intIndex)
Parameters
Returns
- double
The edge distance of the intersection point.
GetEndpoint(int, int)
Gets an endpoint of an input segment.
public Coordinate GetEndpoint(int segmentIndex, int ptIndex)
Parameters
segmentIndex
intthe index of the input segment (0 or 1)
ptIndex
intthe index of the endpoint (0 or 1)
Returns
- Coordinate
The specified endpoint
GetIndexAlongSegment(int, int)
Computes the index (order) of the intIndex'th intersection point in the direction of a specified input line segment.
public int GetIndexAlongSegment(int segmentIndex, int intIndex)
Parameters
Returns
- int
The index of the intersection point along the segment (0 or 1).
GetIntersection(int)
Returns the intIndex'th intersection point.
public Coordinate GetIntersection(int intIndex)
Parameters
intIndex
intis 0 or 1.
Returns
- Coordinate
The intIndex'th intersection point.
GetIntersectionAlongSegment(int, int)
Computes the intIndex'th intersection point in the direction of a specified input line segment.
public Coordinate GetIntersectionAlongSegment(int segmentIndex, int intIndex)
Parameters
Returns
- Coordinate
The intIndex'th intersection point in the direction of the specified input line segment.
IsInteriorIntersection()
Tests whether either intersection point is an interior point of one of the input segments.
public bool IsInteriorIntersection()
Returns
- bool
true
if either intersection point is in the interior of one of the input segment.
IsInteriorIntersection(int)
Tests whether either intersection point is an interior point of the specified input segment.
public bool IsInteriorIntersection(int inputLineIndex)
Parameters
inputLineIndex
int
Returns
- bool
true
if either intersection point is in the interior of the input segment.
IsIntersection(Coordinate)
Test whether a point is a intersection point of two line segments. Note that if the intersection is a line segment, this method only tests for equality with the endpoints of the intersection segment. It does not return true if the input point is internal to the intersection segment.
public bool IsIntersection(Coordinate pt)
Parameters
pt
Coordinate
Returns
- bool
true
if the input point is one of the intersection points.
NonRobustComputeEdgeDistance(Coordinate, Coordinate, Coordinate)
This function is non-robust, since it may compute the square of large numbers. Currently not sure how to improve this.
public static double NonRobustComputeEdgeDistance(Coordinate p, Coordinate p1, Coordinate p2)
Parameters
p
Coordinatep1
Coordinatep2
Coordinate
Returns
ToString()
public override string ToString()