C# Класс Accord.Math.Geometry.LineSegment

The class encapsulates 2D line segment and provides some tool methods related to lines.

The class provides some methods which are related to line segments: distance to point, finding intersection point, etc.

A line segment may be converted to a Line.

Sample usage:

// create a segment LineSegment segment = new LineSegment( new Point( 0, 0 ), new Point( 3, 4 ) ); // get segment's length float length = segment.Length; // get intersection point with a line Point? intersection = segment.GetIntersectionWith( new Line( new Point( -3, 8 ), new Point( 0, 4 ) ) );
Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
DistanceToPoint ( System.Point point ) : float

Calculate Euclidean distance between a point and a finite line segment.

Equals ( object obj ) : bool

Check if this instance of LineSegment equals to the specified one.

GetHashCode ( ) : int

Get hash code for this instance.

GetIntersectionWith ( Line other ) : Point?

Finds, provided it exists, the intersection point with the specified Line.

If the line and the segment do not intersect, the method returns . If the line and the segment share multiple points, the method throws an InvalidOperationException.

GetIntersectionWith ( LineSegment other ) : Point?

Finds, provided it exists, the intersection point with the specified LineSegment.

If the two segments do not intersect, the method returns . If the two segments share multiple points, this throws an InvalidOperationException.

LineSegment ( System.Point start, System.Point end ) : System

Initializes a new instance of the LineSegment class.

ToString ( ) : string

Get string representation of the class.

operator ( ) : bool

Equality operator - checks if two line segments have equal parameters.

Приватные методы

Метод Описание
LocateProjection ( System.Point point ) : ProjectionLocation

Описание методов

DistanceToPoint() публичный метод

Calculate Euclidean distance between a point and a finite line segment.
public DistanceToPoint ( System.Point point ) : float
point System.Point The point to calculate the distance to.
Результат float

Equals() публичный метод

Check if this instance of LineSegment equals to the specified one.
public Equals ( object obj ) : bool
obj object Another line segment to check equalty to.
Результат bool

GetHashCode() публичный метод

Get hash code for this instance.
public GetHashCode ( ) : int
Результат int

GetIntersectionWith() публичный метод

Finds, provided it exists, the intersection point with the specified Line.

If the line and the segment do not intersect, the method returns . If the line and the segment share multiple points, the method throws an InvalidOperationException.

Thrown if this segment is a portion of /// line.
public GetIntersectionWith ( Line other ) : Point?
other Line to find intersection with.
Результат Point?

GetIntersectionWith() публичный метод

Finds, provided it exists, the intersection point with the specified LineSegment.

If the two segments do not intersect, the method returns . If the two segments share multiple points, this throws an InvalidOperationException.

Thrown if the segments overlap - if they have /// multiple points in common.
public GetIntersectionWith ( LineSegment other ) : Point?
other LineSegment to find intersection with.
Результат Point?

LineSegment() публичный метод

Initializes a new instance of the LineSegment class.
Thrown if the two points are the same.
public LineSegment ( System.Point start, System.Point end ) : System
start System.Point Segment's start point.
end System.Point Segment's end point.
Результат System

ToString() публичный метод

Get string representation of the class.
public ToString ( ) : string
Результат string

operator() публичный статический метод

Equality operator - checks if two line segments have equal parameters.
public static operator ( ) : bool
Результат bool