Line

class compas.geometry.Line(p1, p2, **kwargs)[source]

Bases: Primitive

A line is defined by two points.

Parameters
  • p1 ([float, float, float] | Point) – The first point.

  • p2 ([float, float, float] | Point) – The second point.

Attributes
  • start (Point) – The start point of the line.

  • end (Point) – The end point of the line.

  • vector (Vector, read-only) – A vector pointing from start to end.

  • length (float, read-only) – The length of the vector from start to end.

  • direction (Vector, read-only) – A unit vector pointing from start and end.

  • midpoint (Point, read-only) – The midpoint between start and end.

Examples

>>> line = Line([0, 0, 0], [1, 1, 1])
>>> line
Line(Point(0.000, 0.000, 0.000), Point(1.000, 1.000, 1.000))
>>> line.start
Point(0.000, 0.000, 0.000)
>>> line.midpoint
Point(0.500, 0.500, 0.500)
>>> line.length == math.sqrt(1 + 1 + 1)
True
>>> line.direction
Vector(0.577, 0.577, 0.577)

Methods

from_data

Construct a frame from a data dict.

point

A point between start and end at a specific normalized parameter.

transform

Transform this line.

transform_collection

Transform a collection of Line objects.

transformed_collection

Create a collection of transformed Line objects.

Inherited Methods

ToString

Converts the instance to a string.

copy

Make an independent copy of the data object.

from_json

Construct an object from serialized data contained in a JSON file.

from_jsonstring

Construct an object from serialized data contained in a JSON string.

sha256

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

to_data

Convert an object to its native data representation.

to_json

Serialize the data representation of an object to a JSON file.

to_jsonstring

Serialize the data representation of an object to a JSON string.

transformed

Returns a transformed copy of this geometry.

validate_data

Validate the object's data against its data schema.

validate_json

Validate the object's data against its json schema.