Search Results for

    Show / Hide Table of Contents

    Class LineSegment

    Represents a line segment defined by two Coordinates. Provides methods to compute various geometric properties and relationships of line segments. This class is designed to be easily mutable (to the extent of having its contained points public). This supports a common pattern of reusing a single LineSegment object as a way of computing segment properties on the segments defined by arrays or lists of Coordinates.

    Inheritance
    object
    LineSegment
    TaggedLineSegment
    Implements
    IComparable<LineSegment>
    Inherited Members
    object.Equals(object, object)
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    Namespace: NetTopologySuite.Geometries
    Assembly: NetTopologySuite.dll
    Syntax
    [Serializable]
    public class LineSegment : IComparable<LineSegment>

    Constructors

    | Edit this page View Source

    LineSegment()

    Declaration
    public LineSegment()
    | Edit this page View Source

    LineSegment(Coordinate, Coordinate)

    Creates an instance of this class using two coordinates

    Declaration
    public LineSegment(Coordinate p0, Coordinate p1)
    Parameters
    Type Name Description
    Coordinate p0

    The start-point

    Coordinate p1

    The end-point

    | Edit this page View Source

    LineSegment(LineSegment)

    Creates an instance of this class using another instance

    Declaration
    public LineSegment(LineSegment ls)
    Parameters
    Type Name Description
    LineSegment ls
    | Edit this page View Source

    LineSegment(double, double, double, double)

    Creates an instance of this class

    Declaration
    public LineSegment(double x0, double y0, double x1, double y1)
    Parameters
    Type Name Description
    double x0
    double y0
    double x1
    double y1

    Properties

    | Edit this page View Source

    Angle

    Declaration
    public double Angle { get; }
    Property Value
    Type Description
    double

    The angle this segment makes with the x-axis (in radians).

    | Edit this page View Source

    IsHorizontal

    Tests whether the segment is horizontal.

    Declaration
    public bool IsHorizontal { get; }
    Property Value
    Type Description
    bool

    true if the segment is horizontal.

    | Edit this page View Source

    IsVertical

    Tests whether the segment is vertical.

    Declaration
    public bool IsVertical { get; }
    Property Value
    Type Description
    bool

    true if the segment is vertical.

    | Edit this page View Source

    Length

    Computes the length of the line segment.

    Declaration
    public double Length { get; }
    Property Value
    Type Description
    double

    The length of the line segment.

    | Edit this page View Source

    MaxX

    Gets the maximum X ordinate

    Declaration
    public double MaxX { get; }
    Property Value
    Type Description
    double
    | Edit this page View Source

    MaxY

    Gets the maximum Y ordinate

    Declaration
    public double MaxY { get; }
    Property Value
    Type Description
    double
    | Edit this page View Source

    MidPoint

    The midpoint of the segment

    Declaration
    public Coordinate MidPoint { get; }
    Property Value
    Type Description
    Coordinate
    | Edit this page View Source

    MinX

    Gets the minimum X ordinate

    Declaration
    public double MinX { get; }
    Property Value
    Type Description
    double
    | Edit this page View Source

    MinY

    Gets the minimum Y ordinate

    Declaration
    public double MinY { get; }
    Property Value
    Type Description
    double
    | Edit this page View Source

    P0

    The start-point

    Declaration
    public Coordinate P0 { get; set; }
    Property Value
    Type Description
    Coordinate
    | Edit this page View Source

    P1

    The end-point

    Declaration
    public Coordinate P1 { get; set; }
    Property Value
    Type Description
    Coordinate

    Methods

    | Edit this page View Source

    ClosestPoint(Coordinate)

    Computes the closest point on this line segment to another point.

    Declaration
    public Coordinate ClosestPoint(Coordinate p)
    Parameters
    Type Name Description
    Coordinate p

    The point to find the closest point to.

    Returns
    Type Description
    Coordinate

    A Coordinate which is the closest point on the line segment to the point p.

    | Edit this page View Source

    ClosestPoints(LineSegment)

    Computes the closest points on a line segment.

    Declaration
    public Coordinate[] ClosestPoints(LineSegment line)
    Parameters
    Type Name Description
    LineSegment line
    Returns
    Type Description
    Coordinate[]

    A pair of Coordinates which are the closest points on the line segments.

    | Edit this page View Source

    ClosestPoints(LineSegment, ElevationModel)

    Computes the closest points on a line segment.

    Declaration
    public Coordinate[] ClosestPoints(LineSegment line, ElevationModel em)
    Parameters
    Type Name Description
    LineSegment line
    ElevationModel em
    Returns
    Type Description
    Coordinate[]

    A pair of Coordinates which are the closest points on the line segments.

    | Edit this page View Source

    CompareTo(LineSegment)

    Compares this object with the specified object for order. Uses the standard lexicographic ordering for the points in the LineSegment.

    Declaration
    public int CompareTo(LineSegment other)
    Parameters
    Type Name Description
    LineSegment other

    The LineSegment with which this LineSegment is being compared.

    Returns
    Type Description
    int

    A negative integer, zero, or a positive integer as this LineSegment is less than, equal to, or greater than the specified LineSegment.

    | Edit this page View Source

    ComputeMidPoint(Coordinate, Coordinate)

    Computes the midpoint of two coordinates

    Declaration
    public static Coordinate ComputeMidPoint(Coordinate p0, Coordinate p1)
    Parameters
    Type Name Description
    Coordinate p0

    A coordinate

    Coordinate p1

    A coordinate

    Returns
    Type Description
    Coordinate

    The mid point

    Remarks

    This method is named midPoint in JTS.

    | Edit this page View Source

    Distance(Coordinate)

    Computes the distance between this line segment and a point.

    Declaration
    public double Distance(Coordinate p)
    Parameters
    Type Name Description
    Coordinate p
    Returns
    Type Description
    double
    | Edit this page View Source

    Distance(LineSegment)

    Computes the distance between this line segment and another one.

    Declaration
    public double Distance(LineSegment ls)
    Parameters
    Type Name Description
    LineSegment ls
    Returns
    Type Description
    double
    | Edit this page View Source

    DistancePerpendicular(Coordinate)

    Computes the perpendicular distance between the (infinite) line defined by this line segment and a point.

    If the segment has zero length this returns the distance between the segment and the point.
    Declaration
    public double DistancePerpendicular(Coordinate p)
    Parameters
    Type Name Description
    Coordinate p

    The point to compute the distance to

    Returns
    Type Description
    double

    The perpendicular distance between the line and point

    | Edit this page View Source

    DistancePerpendicularOriented(Coordinate)

    Computes the oriented perpendicular distance between the (infinite) line defined by this line segment and a point. The oriented distance is positive if the point on the left of the line, and negative if it is on the right. If the segment has zero length this returns the distance between the segment and the point.

    Declaration
    public double DistancePerpendicularOriented(Coordinate p)
    Parameters
    Type Name Description
    Coordinate p

    The point to compute the distance to

    Returns
    Type Description
    double

    The oriented perpendicular distance between the line and point

    | Edit this page View Source

    Equals(object)

    Returns true if o has the same values for its points.

    Declaration
    public override bool Equals(object o)
    Parameters
    Type Name Description
    object o

    A LineSegment with which to do the comparison.

    Returns
    Type Description
    bool

    true if o is a LineSegment with the same values for the x and y ordinates.

    Overrides
    object.Equals(object)
    | Edit this page View Source

    EqualsTopologically(LineSegment)

    Returns true if other is topologically equal to this LineSegment (e.g. irrespective of orientation).

    Declaration
    public bool EqualsTopologically(LineSegment other)
    Parameters
    Type Name Description
    LineSegment other

    A LineSegment with which to do the comparison.

    Returns
    Type Description
    bool

    true if other is a LineSegment with the same values for the x and y ordinates.

    | Edit this page View Source

    GetCoordinate(int)

    Declaration
    public Coordinate GetCoordinate(int i)
    Parameters
    Type Name Description
    int i
    Returns
    Type Description
    Coordinate
    | Edit this page View Source

    GetHashCode()

    Return HashCode.

    Declaration
    public override int GetHashCode()
    Returns
    Type Description
    int
    Overrides
    object.GetHashCode()
    | Edit this page View Source

    Intersection(LineSegment)

    Computes an intersection point between two segments, if there is one. There may be 0, 1 or many intersection points between two segments. If there are 0, null is returned. If there is 1 or more, a single one is returned (chosen at the discretion of the algorithm). If more information is required about the details of the intersection, the RobustLineIntersector class should be used.

    Declaration
    public Coordinate Intersection(LineSegment line)
    Parameters
    Type Name Description
    LineSegment line

    A line segment

    Returns
    Type Description
    Coordinate

    An intersection point, or null if there is none.

    | Edit this page View Source

    Intersection(LineSegment, ElevationModel)

    Computes an intersection point between two segments, if there is one. There may be 0, 1 or many intersection points between two segments. If there are 0, null is returned. If there is 1 or more, a single one is returned (chosen at the discretion of the algorithm). If more information is required about the details of the intersection, the RobustLineIntersector class should be used.

    Declaration
    public Coordinate Intersection(LineSegment line, ElevationModel em)
    Parameters
    Type Name Description
    LineSegment line

    A line segment

    ElevationModel em

    An elevation model. May be null

    Returns
    Type Description
    Coordinate

    An intersection point, or null if there is none.

    | Edit this page View Source

    LineIntersection(LineSegment)

    Computes the intersection point of the lines defined by two segments, if there is one.

    Declaration
    public Coordinate LineIntersection(LineSegment line)
    Parameters
    Type Name Description
    LineSegment line

    A line segment defining a straight line

    Returns
    Type Description
    Coordinate

    An intersection point, or null if there is none or an infinite number

    Remarks

    There may be 0, 1 or an infinite number of intersection points between two lines. If there is a unique intersection point, it is returned. Otherwise, null is returned. If more information is required about the details of the intersection, the RobustLineIntersector class should be used.

    See Also
    RobustLineIntersector
    | Edit this page View Source

    Normalize()

    Puts the line segment into a normalized form. This is useful for using line segments in maps and indexes when topological equality rather than exact equality is desired.

    Declaration
    public void Normalize()
    | Edit this page View Source

    Offset(double)

    Computes the LineSegment that is offset from the segment by a given distance. The computed segment is offset to the left of the line if the offset distance is positive, to the right if negative.

    Declaration
    public LineSegment Offset(double offsetDistance)
    Parameters
    Type Name Description
    double offsetDistance

    The distance the point is offset from the segment (positive is to the left, negative is to the right)

    Returns
    Type Description
    LineSegment

    A line segment offset by the specified distance

    Exceptions
    Type Condition
    ApplicationException

    Thrown if the segment has zero length

    | Edit this page View Source

    OrientationIndex(Coordinate)

    Determines the orientation index of a Coordinate relative to this segment. The orientation index is as defined in Index(Coordinate, Coordinate, Coordinate).

    Declaration
    public int OrientationIndex(Coordinate p)
    Parameters
    Type Name Description
    Coordinate p
    Returns
    Type Description
    int
    1if p is to the left of this segment
    -1if p is to the right of this segment
    0if p is collinear with this segment
    "
    | Edit this page View Source

    OrientationIndex(LineSegment)

    Determines the orientation of a LineSegment relative to this segment. The concept of orientation is specified as follows: Given two line segments A and L, A is to the left of a segment L if A lies wholly in the closed half-plane lying to the left of L A is to the right of a segment L if A lies wholly in the closed half-plane lying to the right of L otherwise, A has indeterminate orientation relative to L. This happens if A is collinear with L or if A crosses the line determined by L.

    Declaration
    public int OrientationIndex(LineSegment seg)
    Parameters
    Type Name Description
    LineSegment seg

    The LineSegment to compare.

    Returns
    Type Description
    int

    1 if seg is to the left of this segment, -1 if seg is to the right of this segment, 0 if seg is collinear to or crosses this segment.

    | Edit this page View Source

    PointAlong(double)

    Computes the Coordinate that lies a given fraction along the line defined by this segment.

    Declaration
    public Coordinate PointAlong(double segmentLengthFraction)
    Parameters
    Type Name Description
    double segmentLengthFraction

    the fraction of the segment length along the line

    Returns
    Type Description
    Coordinate

    the point at that distance

    Remarks

    A fraction of 0.0 returns the start point of the segment; A fraction of 1.0 returns the end point of the segment. If the fraction is < 0.0 or > 1.0 the point returned will lie before the start or beyond the end of the segment.

    | Edit this page View Source

    PointAlongOffset(double, double)

    Computes the Coordinate that lies a given

    Declaration
    public Coordinate PointAlongOffset(double segmentLengthFraction, double offsetDistance)
    Parameters
    Type Name Description
    double segmentLengthFraction

    the fraction of the segment length along the line

    double offsetDistance

    the distance the point is offset from the segment

    Returns
    Type Description
    Coordinate

    the point at that distance and offset

    Remarks

    A fraction along the line defined by this segment and offset from the segment by a given distance. A fraction of 0.0 offsets from the start point of the segment; A fraction of 1.0 offsets from the end point of the segment. The computed point is offset to the left of the line if the offset distance is positive, to the right if negative.

    Exceptions
    Type Condition
    ApplicationException

    if the segment has zero length

    | Edit this page View Source

    Project(Coordinate)

    Compute the projection of a point onto the line determined by this line segment. Note that the projected point may lie outside the line segment. If this is the case, the projection factor will lie outside the range [0.0, 1.0].

    Declaration
    public Coordinate Project(Coordinate p)
    Parameters
    Type Name Description
    Coordinate p
    Returns
    Type Description
    Coordinate
    | Edit this page View Source

    Project(LineSegment)

    Project a line segment onto this line segment and return the resulting line segment. The returned line segment will be a subset of the target line line segment. This subset may be null, if the segments are oriented in such a way that there is no projection. Note that the returned line may have zero length (i.e. the same endpoints). This can happen for instance if the lines are perpendicular to one another.

    Declaration
    public LineSegment Project(LineSegment seg)
    Parameters
    Type Name Description
    LineSegment seg

    The line segment to project.

    Returns
    Type Description
    LineSegment

    The projected line segment, or null if there is no overlap.

    | Edit this page View Source

    ProjectionFactor(Coordinate)

    Computes the Projection Factor for the projection of the point p onto this LineSegment. The Projection Factor is the constant r by which the vector for this segment must be multiplied to equal the vector for the projection of p on the line defined by this segment.

    The projection factor will lie in the range (-inf, +inf), or be NaN if the line segment has zero length.
    Declaration
    public double ProjectionFactor(Coordinate p)
    Parameters
    Type Name Description
    Coordinate p

    The point to compute the factor for

    Returns
    Type Description
    double

    The projection factor for the point

    | Edit this page View Source

    Reflect(Coordinate)

    Computes the reflection of a point in the line defined by this line segment.

    Declaration
    public Coordinate Reflect(Coordinate p)
    Parameters
    Type Name Description
    Coordinate p

    The point to reflect

    Returns
    Type Description
    Coordinate

    The reflected point

    | Edit this page View Source

    Reverse()

    Reverses the direction of the line segment.

    Declaration
    public void Reverse()
    | Edit this page View Source

    SegmentFraction(Coordinate)

    Computes the fraction of distance (in [0.0, 1.0]) that the projection of a point occurs along this line segment. If the point is beyond either ends of the line segment, the closest fractional value (0.0 or 1.0) is returned.

    Declaration
    public double SegmentFraction(Coordinate inputPt)
    Parameters
    Type Name Description
    Coordinate inputPt

    the point

    Returns
    Type Description
    double

    the fraction along the line segment the projection of the point occurs

    Remarks

    Essentially, this is the ProjectionFactor(Coordinate) clamped to the range [0.0, 1.0].

    | Edit this page View Source

    SetCoordinates(Coordinate, Coordinate)

    Declaration
    public void SetCoordinates(Coordinate p0, Coordinate p1)
    Parameters
    Type Name Description
    Coordinate p0
    Coordinate p1
    | Edit this page View Source

    SetCoordinates(LineSegment)

    Declaration
    public void SetCoordinates(LineSegment ls)
    Parameters
    Type Name Description
    LineSegment ls
    | Edit this page View Source

    ToGeometry(GeometryFactory)

    Creates a LineString with the same coordinates as this segment

    Declaration
    public LineString ToGeometry(GeometryFactory geomFactory)
    Parameters
    Type Name Description
    GeometryFactory geomFactory

    the geometry factory to use

    Returns
    Type Description
    LineString

    A LineString with the same geometry as this segment

    | Edit this page View Source

    ToString()

    Declaration
    public override string ToString()
    Returns
    Type Description
    string
    Overrides
    object.ToString()

    Operators

    | Edit this page View Source

    operator ==(LineSegment, LineSegment)

    Declaration
    public static bool operator ==(LineSegment obj1, LineSegment obj2)
    Parameters
    Type Name Description
    LineSegment obj1
    LineSegment obj2
    Returns
    Type Description
    bool
    | Edit this page View Source

    operator !=(LineSegment, LineSegment)

    Declaration
    public static bool operator !=(LineSegment obj1, LineSegment obj2)
    Parameters
    Type Name Description
    LineSegment obj1
    LineSegment obj2
    Returns
    Type Description
    bool

    Implements

    IComparable<T>
    • Edit this page
    • View Source
    In this article
    Back to top Generated by DocFX