Click or drag to resize
Accord.NET (logo)

Line Class

The class encapsulates 2D line and provides some tool methods related to lines.
Inheritance Hierarchy
SystemObject
  Accord.Math.GeometryLine

Namespace:  Accord.Math.Geometry
Assembly:  Accord.Math (in Accord.Math.dll) Version: 3.8.0
Syntax
public sealed class Line
Request Example View Source

The Line type exposes the following members.

Properties
  NameDescription
Public propertyIntercept
If not IsVertical, gets the Line's Y-intercept. If IsVertical gets the line's X-intercept.
Public propertyIsHorizontal
Checks if the line horizontal or not.
Public propertyIsVertical
Checks if the line vertical or not.
Public propertySlope
Gets the slope of the line.
Top
Methods
  NameDescription
Public methodDistanceToPoint
Calculate Euclidean distance between a point and a line.
Public methodEquals
Check if this instance of Line equals to the specified one.
(Overrides ObjectEquals(Object).)
Public methodStatic memberFromPoints
Creates a Line that goes through the two specified points.
Public methodStatic memberFromPointTheta
Constructs a Line from a point and an angle (in degrees).
Public methodStatic memberFromRTheta
Constructs a Line from a radius and an angle (in degrees).
Public methodStatic memberFromSlopeIntercept
Creates a Line with the specified slope and intercept.
Public methodGetAngleBetweenLines
Calculate minimum angle between this line and the specified line measured in [0, 90] degrees range.
Public methodGetHashCode
Get hash code for this instance.
(Overrides ObjectGetHashCode.)
Public methodGetIntersectionWith(Line)
Finds intersection point with the specified line.
Public methodGetIntersectionWith(LineSegment)
Finds, provided it exists, the intersection point with the specified LineSegment.
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodToString
Get string representation of the class.
(Overrides ObjectToString.)
Top
Operators
  NameDescription
Public operatorStatic memberEquality
Equality operator - checks if two lines have equal parameters.
Public operatorStatic memberInequality
Inequality operator - checks if two lines have different parameters.
Top
Extension Methods
  NameDescription
Public Extension MethodHasMethod
Checks whether an object implements a method with the given name.
(Defined by ExtensionMethods.)
Public Extension MethodIsEqual
Compares two objects for equality, performing an elementwise comparison if the elements are vectors or matrices.
(Defined by Matrix.)
Public Extension MethodTo(Type)Overloaded.
Converts an object into another type, irrespective of whether the conversion can be done at compile time or not. This can be used to convert generic types to numeric types during runtime.
(Defined by ExtensionMethods.)
Public Extension MethodToTOverloaded.
Converts an object into another type, irrespective of whether the conversion can be done at compile time or not. This can be used to convert generic types to numeric types during runtime.
(Defined by ExtensionMethods.)
Top
Remarks

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, would normally be meaningless, and it would be impossible to distinguish the line x = 5 from the line x = -5. Therefore, if Slope is PositiveInfinity or NegativeInfinity, the line's equation is instead x = Intercept.

Sample usage:

// create a line
Line line = Line.FromPoints( new Point( 0, 0 ), new Point( 3, 4 ) );
// check if it is vertical or horizontal
if ( line.IsVertical || line.IsHorizontal )
{
    // ...
}

// get intersection point with another line
Point intersection = line.GetIntersectionWith(
    Line.FromPoints( new Point( 3, 0 ), new Point( 0, 4 ) ) );
See Also