Line

class compas.geometry.Line[source]

Bases: Curve

A line is a curve defined by two points.

The first point is the start point of the line. The second point is the end point of the line. The vector between the two points defines the direction of the line. The length of the vector is the length of the line. The direction vector is the unit vector of the vector between start and end. The parameterisation of the line is such that the start point corresponds to t = 0 and the end point to t = 1.

The coordinate system of a line is always the world coordinate system (WCS). Transformation of a line is performed by transforming the start and end point.

Parameters:
start[float, float, float] | compas.geometry.Point

The first point.

end[float, float, float] | compas.geometry.Point

The second point.

namestr, optional

The name of the line.

Attributes:
startcompas.geometry.Point

The start point of the line.

endcompas.geometry.Point

The end point of the line.

vectorcompas.geometry.Vector, read-only

A vector pointing from start to end.

lengthfloat, read-only

Compute the length of the curve.

directioncompas.geometry.Vector, read-only

A unit vector parallel to the line vector.

midpointcompas.geometry.Point, read-only

The midpoint between start and end.

framecompas.geometry.Frame, read-only

The frame of the line. This is alsways the world XY frame.

transformationcompas.geometry.Transformation, read-only

This is always the identity transformation.

Examples

>>> line = Line([0, 0, 0], [1, 1, 1])
>>> print(line.start)
Point(x=0.000, y=0.000, z=0.000)
>>> print(line.midpoint)
Point(x=0.500, y=0.500, z=0.500)
>>> line.length == line.vector.length
True
>>> print(line.direction)
Vector(x=0.577, y=0.577, z=0.577)

Methods

closest_point

Compute the closest point on the line to a given point.

flip

Flip the direction of the line.

flipped

Return a new line with the direction flipped.

from_point_and_vector

Construct a line from a point and a vector.

from_point_direction_length

Construct a line from a point, a direction and a length.

point_at

Construct a point along the line at a fractional position.

point_from_end

Construct a point along the line at a distance from the end point.

point_from_start

Construct a point along the line at a distance from the start point.

transform

Transform this line.

Inherited Methods

ToString

Converts the instance to a string.

aabb

Compute the axis-aligned bounding box of the curve.

compute_aabb

Compute the axis-aligned bounding box of the geometry.

compute_obb

Compute the oriented bounding box of the geometry.

copy

Make an independent copy of the data object.

curvature_at

Compute the curvature vector of the curve at a parameter.

divide_by_count

Compute the curve parameters that divide the curve into a specific number of equal length segments.

divide_by_length

Compute the curve parameters that divide the curve into segments of specified length.

fair

frame_at

Compute the local frame of the curve at a parameter.

from_json

Construct an object of this type from a JSON file.

from_jsonstring

Construct an object of this type from a JSON string.

from_native

Construct a parametric curve from a native curve geometry.

from_obj

Load a curve from an OBJ file.

from_step

Load a curve from a STP file.

normal_at

Compute the normal of the curve at a parameter.

offset

reverse

Reverse the parametrisation of the curve.

reversed

Reverse a copy of the curve.

rotate

Rotate the geometry.

rotated

Returns a rotated copy of this geometry.

scale

Scale the geometry.

scaled

Returns a scaled copy of this geometry.

sha256

Compute a hash of the data for comparison during version control using the sha256 algorithm.

smooth

split

tangent_at

Compute the tangent vector of the curve at a parameter.

to_json

Convert an object to its native data representation and save it to a JSON file.

to_jsonstring

Convert an object to its native data representation and save it to a JSON string.

to_obj

Write the curve geometry to an OBJ file.

to_points

Convert the curve to a list of points.

to_polygon

Convert the curve to a polygon.

to_polyline

Convert the curve to a polyline.

to_step

Write the curve geometry to a STP file.

transformed

Returns a transformed copy of this geometry.

translate

Translate the geometry.

translated

Returns a translated copy of this geometry.

trim

validate_data

Validate the data against the object's data schema.