Class LineIntersector
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).
Inherited Members
Namespace: NetTopologySuite.Algorithm
Assembly: NetTopologySuite.dll
Syntax
public abstract class LineIntersector
Constructors
| Improve this Doc View SourceLineIntersector()
Creates an instance of this class
Declaration
protected LineIntersector()
Fields
| Improve this Doc View SourceCollinearIntersection
Indicates that line segments intersect in a line segment
Declaration
public const int CollinearIntersection = 2
Field Value
Type | Description |
---|---|
Int32 |
InputLines
Array of coordinate arrays forming the lines
Declaration
protected Coordinate[][] InputLines
Field Value
Type | Description |
---|---|
Coordinate[][] |
IntersectionLineIndex
The indexes of the endpoints of the intersection lines, in order along the corresponding line
Declaration
protected int[] IntersectionLineIndex
Field Value
Type | Description |
---|---|
Int32[] |
IntersectionPoint
Array of
Declaration
protected Coordinate[] IntersectionPoint
Field Value
Type | Description |
---|---|
Coordinate[] |
NoIntersection
Indicates that line segments do not intersect
Declaration
public const int NoIntersection = 0
Field Value
Type | Description |
---|---|
Int32 |
PointIntersection
Indicates that line segments intersect in a single point
Declaration
public const int PointIntersection = 1
Field Value
Type | Description |
---|---|
Int32 |
Result
A value indicating the intersection result
Possible values are:
Declaration
protected int Result
Field Value
Type | Description |
---|---|
Int32 |
Properties
| Improve this Doc View SourceHasIntersection
Tests whether the input geometries intersect.
Declaration
public bool HasIntersection { get; }
Property Value
Type | Description |
---|---|
Boolean |
|
IntersectionNum
Returns the number of intersection points found. This will be either 0, 1 or 2.
Declaration
public int IntersectionNum { get; }
Property Value
Type | Description |
---|---|
Int32 | The number of intersection points found (0, 1, or 2) |
IsCollinear
Gets a value indicating if the computed intersection is collinear
Declaration
protected bool IsCollinear { get; }
Property Value
Type | Description |
---|---|
Boolean |
IsEndPoint
Gets a value indicating if the intersection is an end-point intersection
Declaration
protected bool IsEndPoint { get; }
Property Value
Type | Description |
---|---|
Boolean |
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).
Declaration
public bool IsProper { get; protected set; }
Property Value
Type | Description |
---|---|
Boolean |
|
Pa
Alias the IntersectionPoint[0] for ease of reference
Declaration
protected Coordinate Pa { get; }
Property Value
Type | Description |
---|---|
Coordinate |
Pb
Alias the IntersectionPoint[1] for ease of reference
Declaration
protected Coordinate Pb { get; }
Property Value
Type | Description |
---|---|
Coordinate |
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.
Declaration
public PrecisionModel PrecisionModel { get; set; }
Property Value
Type | Description |
---|---|
PrecisionModel |
Methods
| Improve this Doc View SourceComputeEdgeDistance(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.
Declaration
public static double ComputeEdgeDistance(Coordinate p, Coordinate p0, Coordinate p1)
Parameters
Type | Name | Description |
---|---|---|
Coordinate | p | |
Coordinate | p0 | |
Coordinate | p1 |
Returns
Type | Description |
---|---|
Double |
ComputeIntersect(Coordinate, Coordinate, Coordinate, Coordinate)
Computes the intersection of two line segments, one defined by p1
and p2
,
the other by q1
and q2
.
Declaration
public abstract int ComputeIntersect(Coordinate p1, Coordinate p2, Coordinate q1, Coordinate q2)
Parameters
Type | Name | Description |
---|---|---|
Coordinate | p1 | The 1st point of the 1st segment |
Coordinate | p2 | The 2nd point of the 1st segment |
Coordinate | q1 | The 1st point of the 2nd segment |
Coordinate | q2 | The 2nd point of the 2nd segment |
Returns
Type | Description |
---|---|
Int32 |
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
.
Declaration
public abstract void ComputeIntersection(Coordinate p, Coordinate p1, Coordinate p2)
Parameters
Type | Name | Description |
---|---|---|
Coordinate | p | |
Coordinate | p1 | |
Coordinate | p2 |
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).
Declaration
public void ComputeIntersection(Coordinate p1, Coordinate p2, Coordinate p3, Coordinate p4)
Parameters
Type | Name | Description |
---|---|---|
Coordinate | p1 | The 1st point of the 1st segment |
Coordinate | p2 | The 2nd point of the 1st segment |
Coordinate | p3 | The 1st point of the 2nd segment |
Coordinate | p4 | The 2nd point of the 2nd segment |
ComputeIntLineIndex()
Computes the IntersectionLineIndex values.
Declaration
protected void ComputeIntLineIndex()
ComputeIntLineIndex(Int32)
Computes the intersection line index
Declaration
protected void ComputeIntLineIndex(int segmentIndex)
Parameters
Type | Name | Description |
---|---|---|
Int32 | segmentIndex | The segment index |
GetEdgeDistance(Int32, Int32)
Computes the "edge distance" of an intersection point along the specified input line segment.
Declaration
public double GetEdgeDistance(int segmentIndex, int intIndex)
Parameters
Type | Name | Description |
---|---|---|
Int32 | segmentIndex | is 0 or 1. |
Int32 | intIndex | is 0 or 1. |
Returns
Type | Description |
---|---|
Double | The edge distance of the intersection point. |
GetEndpoint(Int32, Int32)
Gets an endpoint of an input segment.
Declaration
public Coordinate GetEndpoint(int segmentIndex, int ptIndex)
Parameters
Type | Name | Description |
---|---|---|
Int32 | segmentIndex | the index of the input segment (0 or 1) |
Int32 | ptIndex | the index of the endpoint (0 or 1) |
Returns
Type | Description |
---|---|
Coordinate | The specified endpoint |
GetIndexAlongSegment(Int32, Int32)
Computes the index (order) of the intIndex'th intersection point in the direction of a specified input line segment.
Declaration
public int GetIndexAlongSegment(int segmentIndex, int intIndex)
Parameters
Type | Name | Description |
---|---|---|
Int32 | segmentIndex | is 0 or 1. |
Int32 | intIndex | is 0 or 1. |
Returns
Type | Description |
---|---|
Int32 | The index of the intersection point along the segment (0 or 1). |
GetIntersection(Int32)
Returns the intIndex'th intersection point.
Declaration
public Coordinate GetIntersection(int intIndex)
Parameters
Type | Name | Description |
---|---|---|
Int32 | intIndex | is 0 or 1. |
Returns
Type | Description |
---|---|
Coordinate | The intIndex'th intersection point. |
GetIntersectionAlongSegment(Int32, Int32)
Computes the intIndex'th intersection point in the direction of a specified input line segment.
Declaration
public Coordinate GetIntersectionAlongSegment(int segmentIndex, int intIndex)
Parameters
Type | Name | Description |
---|---|---|
Int32 | segmentIndex | is 0 or 1. |
Int32 | intIndex | is 0 or 1. |
Returns
Type | Description |
---|---|
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.
Declaration
public bool IsInteriorIntersection()
Returns
Type | Description |
---|---|
Boolean |
|
IsInteriorIntersection(Int32)
Tests whether either intersection point is an interior point of the specified input segment.
Declaration
public bool IsInteriorIntersection(int inputLineIndex)
Parameters
Type | Name | Description |
---|---|---|
Int32 | inputLineIndex |
Returns
Type | Description |
---|---|
Boolean |
|
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.
Declaration
public bool IsIntersection(Coordinate pt)
Parameters
Type | Name | Description |
---|---|---|
Coordinate | pt |
Returns
Type | Description |
---|---|
Boolean |
|
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.
Declaration
public static double NonRobustComputeEdgeDistance(Coordinate p, Coordinate p1, Coordinate p2)
Parameters
Type | Name | Description |
---|---|---|
Coordinate | p | |
Coordinate | p1 | |
Coordinate | p2 |
Returns
Type | Description |
---|---|
Double |
ToString()
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
String |