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 ) ) );
파일 보기 프로젝트 열기: holisticware-admin/MonoVersal.AForgeNET 1 사용 예제들

공개 메소드들

메소드 설명
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