Skip to content

Line2D

Canonical path: NemAll_Python_Geometry.Line2D

Representation of a two-dimensional line

EndPoint property writable

EndPoint: Point2D

Get the end point in world coordinate system

EndRelPoint property writable

EndRelPoint: Point2D

Get the end point in relative coordinate system.

RefPoint property writable

RefPoint: Point2D

Get the reference point.

Coordinates of points will be recalculated with new reference point. Formula: m_Points[i] = m_RefPoint + m_Points[i] - refPoint

StartPoint property writable

StartPoint: Point2D

Get the start point in world coordinate system.

StartRelPoint property writable

StartRelPoint: Point2D

Get the start point in relative coordinate system

To3D property

To3D: Line3D

convert to 3D3

EqualRef

EqualRef(line: Line2D) -> bool

Check, whether the reference point of another line is equal to the reference point of this line.

Reference point of a line is by default (0,0), regardless of the start point of the line.

Parameters:

  • line (Line2D) –

    Line to compare

Returns:

  • bool

    True if the reference points are equal, False otherwise

Examples:

>>> this_line = Line2D(0, 0, 1, 1)
>>> this_line.EqualRef(Line2D(1, 1, 2, 2))
True
>>> this_line.RefPoint = Point2D(1, 1)
>>> this_line.EqualRef(Line2D(1, 1, 2, 2))
False

Extend

Extend(delta: float)

Extend the line at the end

Parameters:

  • delta (float) –

    size of extension

Examples:

line_4 is a line from (0, 0) to (5, 5). Extending it by 1.0 results in:

>>> line_4.Extend(1.0)
>>> line_4
Line2D(0, 0, 5.707..., 5.707...)

Extending by a negative value trims the line:

>>> line_4.Extend(-1.0)
>>> line_4
Line2D(0, 0, 5, 5)

GetAngle

GetAngle() -> Angle

Get angle between X axis and the line

Returns:

  • Angle

    Angle normalized to [0, 2*pi]

Examples:

>>> Line2D(0, 0, 1, 1).GetAngle().Deg
45.0...
>>> Line2D(0, 0, 1, -1).GetAngle().Deg
315.0...

GetCenterPoint

GetCenterPoint() -> Point2D

Get the center point in world coordinate system

Returns:

  • Point2D

    Center point in world coordinate system

Examples:

line_4 is a line from (0, 0) to (5, 5). The center point is at:

>>> line_4.GetCenterPoint()
Point2D(2.5, 2.5)

GetCoords

GetCoords() -> tuple[float, float, float, float]

Get coordinates in world coordinate.

Returns:

  • float

    Start point X coordinate

  • float

    Start point Y coordinate

  • float

    End point X coordinate

  • float

    End point Y coordinate

GetEndPoint

GetEndPoint() -> Point2D

Get the end point in world coordinate system

Returns:

GetEndRelPoint

GetEndRelPoint() -> Point2D

Get the end point in relative coordinate system.

Returns:

GetRefPoint

GetRefPoint() -> Point2D

Get the reference point.

Returns:

GetStartPoint

GetStartPoint() -> Point2D

Get the start point in world coordinate system.

Returns:

GetStartRelPoint

GetStartRelPoint() -> Point2D

Get the start point in relative coordinate system

Returns:

GetVector

GetVector() -> Vector2D

Get the vector.

Returns:

  • Vector2D

    Vector from the start to the end point

Examples:

>>> Line2D(1, 1, 2, 2).GetVector()
Vector2D(1, 1)

IsPoint

IsPoint() -> bool

Check, whether the line is a point (start point equal end point)

Returns:

  • bool

    Line is a point: true/false

Reverse

Reverse()

Reverse orientation of the line

Set overloaded

Set(line: Line2D)

Initialize line from line.

Parameters:

Set(x1: float, y1: float, x2: float, y2: float)

Set line points in world coordinate system.

Used world coordinates.

Parameters:

  • x1 (float) –

    X coordinate of start point.

  • y1 (float) –

    Y coordinate of start point.

  • x2 (float) –

    X coordinate of end point.

  • y2 (float) –

    Y coordinate of end point.

Set(point1: Point2D, point2: Point2D)

Set line points in world coordinate system.

Set line from two points. Used world coordinates.

Parameters:

  • point1 (Point2D) –

    Point2D start point of line.

  • point2 (Point2D) –

    Point2D end point of line.

Set(refPoint: Point2D, point1: Point2D, point2: Point2D)

Set line points.

Used local coordinate system for point1 and point2. refPoint used global coordinate system.

Parameters:

  • refPoint (Point2D) –

    refPoint reference point of line.

  • point1 (Point2D) –

    Point2D start point of line.

  • point2 (Point2D) –

    Point2D end point of line.

SetEndPoint

SetEndPoint(endPoint: Point2D)

Set end point in world coordinate system.

Parameters:

  • endPoint (Point2D) –

    New start point.

SetEndRelPoint

SetEndRelPoint(endPoint: Point2D)

Set end point in local coordinate system.

Parameters:

  • endPoint (Point2D) –

    New start point.

SetRefPoint

SetRefPoint(refPoint: Point2D)

Set reference point in world coordinate system.

Coordinates of points will be recalculated with new reference point. Formula: m_Points[i] = m_RefPoint + m_Points[i] - refPoint

Parameters:

  • refPoint (Point2D) –

    new reference point.

SetStartPoint

SetStartPoint(startPoint: Point2D)

Set start point in world coordinate system.

Parameters:

  • startPoint (Point2D) –

    New start point.

SetStartRelPoint

SetStartRelPoint(startPoint: Point2D)

Set start point in local coordinate system.

Parameters:

  • startPoint (Point2D) –

    New start point.

TrimEnd

TrimEnd(ds: float)

Trim the line at the end

Parameters:

  • ds (float) –

    The length by which the line will be trimmed. Negative value extends the line.

Examples:

line_4 is a line from (0, 0) to (5, 5). Trimming it by 1.0 results in:

>>> line_4.TrimEnd(1.0)
>>> line_4
Line2D(0, 0, 4.292..., 4.292...)

Trimming by a negative value extends the line:

>>> line_4.TrimEnd(-1.0)
>>> line_4
Line2D(0, 0, 5, 5)

TrimStart

TrimStart(ds: float)

Trim the line at the start

Parameters:

  • ds (float) –

    The length by which the line will be trimmed. Negative value extends the line.

Raises:

  • ValueError

    When the ds length is larger than the line's length.

__eq__

__eq__(line: Line2D) -> bool

Comparison of lines.

Be careful, this method work without tolerance!

Parameters:

  • line (Line2D) –

    line to be compared.

Returns:

  • bool

    True when lines are equal, otherwise false.

__init__ overloaded

__init__()

Initialize

__init__(line: Line2D)

Copy constructor.

Parameters:

  • line (Line2D) –

    Line which will be copied.

__init__(line3D: Line3D)

Copy constructor to convert a 3D line

Parameters:

__init__(point1: Point2D, point2: Point2D)

Constructor.

Initialize line from two points. Reference point is initialized to [0.0, 0.0]. Used world coordinates.

Parameters:

  • point1 (Point2D) –

    Point2D start point of line.

  • point2 (Point2D) –

    Point2D end point of line.

__init__(startPoint: Point2D, vec: Vector2D)

Constructor.

Initialize line from point and relative vector to point. Reference point is initialized to [0.0, 0.0]. Used world coordinates.

Parameters:

  • startPoint (Point2D) –

    Point2D start point of line.

  • vec (Vector2D) –

    Vector2D vector of end point relative to the point1.

__init__(x1: float, y1: float, x2: float, y2: float)

Constructor.

Reference point is initialized to [0.0, 0.0]. Used world coordinates.

Parameters:

  • x1 (float) –

    X coordinate of start point.

  • y1 (float) –

    Y coordinate of start point.

  • x2 (float) –

    X coordinate of end point.

  • y2 (float) –

    Y coordinate of end point.

__init__(refPoint: Point2D, point1: Point2D, point2: Point2D)

Constructor.

Used local coordinate system for point1 and point2. refPoint used global coordinate system.

Parameters:

  • refPoint (Point2D) –

    reference point of line.

  • point1 (Point2D) –

    start point of line.

  • point2 (Point2D) –

    end point of line.

__mul__

__mul__(matrix: Matrix2D) -> Line2D

Matrix transformation.

Parameters:

  • matrix (Matrix2D) –

    transformation matrix.

Returns:

  • Line2D

    Line2D transformed line.

__repr__

__repr__() -> str

Convert to string

Placeholder