C# Класс AForge.Math.Geometry.Line

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

The class provides some methods which are related to lines: angle between lines, distance to point, finding intersection point, etc.

Generally, the equation of the line is y = Slope * x + Intercept. However, when Slope is an Infinity, Intercept would normally be meaningless, and it would be impossible to distinguish the line x = 5 from the line x = -5. Therefore, if Slope is Double.PositiveInfinity or Double.NegativeInfinity, the line's equation is instead x = Intercept.

Sample usage:

// create a line Line line = Line.FromPoints( new DoublePoint( 0, 0 ), new DoublePoint( 3, 4 ) ); // check if it is vertical or horizontal if ( line.IsVertical || line.IsHorizontal ) { // ... } // get intersection point with another line DoublePoint intersection = line.GetIntersectionWith( Line.FromPoints( new DoublePoint( 3, 0 ), new DoublePoint( 0, 4 ) ) );
Показать файл Открыть проект Примеры использования класса

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

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

Calculate Euclidean distance between a point and a line.

Equals ( object obj ) : bool

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

FromPointTheta ( Point point, float theta ) : Line

Constructs a Line from a point and an angle (in degrees).

theta is the counterclockwise rotation from the positive X axis to the vector through the origin and normal to the line.

This means that if theta is in [0,180), the point on the line closest to the origin is on the positive X or Y axes, or in quadrants I or II. Likewise, if theta is in [180,360), the point on the line closest to the origin is on the negative X or Y axes, or in quadrants III or IV.

FromPoints ( Point point1, Point point2 ) : Line

Creates a Line that goes through the two specified points.

FromRTheta ( float radius, float theta ) : Line

Constructs a Line from a radius and an angle (in degrees).

radius is the minimum distance from the origin to the line, and theta is the counterclockwise rotation from the positive X axis to the vector through the origin and normal to the line.

This means that if theta is in [0,180), the point on the line closest to the origin is on the positive X or Y axes, or in quadrants I or II. Likewise, if theta is in [180,360), the point on the line closest to the origin is on the negative X or Y axes, or in quadrants III or IV.

FromSlopeIntercept ( float slope, float intercept ) : Line

Creates a Line with the specified slope and intercept.

The construction here follows the same rules as for the rest of this class. Most lines are expressed as y = slope * x + intercept. Vertical lines, however, are x = intercept. This is indicated by IsVertical being true or by Slope returning float.PositiveInfinity or float.NegativeInfinity.

GetAngleBetweenLines ( Line secondLine ) : float

Calculate minimum angle between this line and the specified line measured in [0, 90] degrees range.

GetHashCode ( ) : int

Get hash code for this instance.

GetIntersectionWith ( Line secondLine ) : Point?

Finds intersection point with the specified line.

GetIntersectionWith ( LineSegment other ) : Point?

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

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

ToString ( ) : string

Get string representation of the class.

operator ( ) : bool

Equality operator - checks if two lines have equal parameters.

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

Метод Описание
Line ( Point start, Point end ) : System
Line ( Point point, float theta ) : System
Line ( float slope, float intercept ) : System
Line ( float radius, float theta, bool unused ) : System
Throw ( float radius ) : void

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

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

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

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

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

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

Constructs a Line from a point and an angle (in degrees).

theta is the counterclockwise rotation from the positive X axis to the vector through the origin and normal to the line.

This means that if theta is in [0,180), the point on the line closest to the origin is on the positive X or Y axes, or in quadrants I or II. Likewise, if theta is in [180,360), the point on the line closest to the origin is on the negative X or Y axes, or in quadrants III or IV.

public static FromPointTheta ( Point point, float theta ) : Line
point Point The minimum distance from the line to the origin.
theta float The angle of the normal vector from the origin to the line.
Результат Line

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

Creates a Line that goes through the two specified points.
Thrown if the two points are the same.
public static FromPoints ( Point point1, Point point2 ) : Line
point1 Point One point on the line.
point2 Point Another point on the line.
Результат Line

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

Constructs a Line from a radius and an angle (in degrees).

radius is the minimum distance from the origin to the line, and theta is the counterclockwise rotation from the positive X axis to the vector through the origin and normal to the line.

This means that if theta is in [0,180), the point on the line closest to the origin is on the positive X or Y axes, or in quadrants I or II. Likewise, if theta is in [180,360), the point on the line closest to the origin is on the negative X or Y axes, or in quadrants III or IV.

Thrown if radius is negative.
public static FromRTheta ( float radius, float theta ) : Line
radius float The minimum distance from the line to the origin.
theta float The angle of the vector from the origin to the line.
Результат Line

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

Creates a Line with the specified slope and intercept.

The construction here follows the same rules as for the rest of this class. Most lines are expressed as y = slope * x + intercept. Vertical lines, however, are x = intercept. This is indicated by IsVertical being true or by Slope returning float.PositiveInfinity or float.NegativeInfinity.

public static FromSlopeIntercept ( float slope, float intercept ) : Line
slope float The slope of the line
intercept float The Y-intercept of the line, unless the slope is an /// infinity, in which case the line's equation is "x = intercept" instead.
Результат Line

GetAngleBetweenLines() публичный Метод

Calculate minimum angle between this line and the specified line measured in [0, 90] degrees range.
public GetAngleBetweenLines ( Line secondLine ) : float
secondLine Line The line to find angle between.
Результат float

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

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

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

Finds intersection point with the specified line.
Thrown if the specified line is the same line as this line.
public GetIntersectionWith ( Line secondLine ) : Point?
secondLine Line Line to find intersection with.
Результат Point?

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

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

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

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

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

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

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

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