compas.geometry.Line

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

Bases: compas.geometry.primitives._primitive.Primitive

A line is defined by two points.

Parameters
  • p1 (point) – The first point.

  • p2 (point) – The second point.

Attributes

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

copy([cls])

Make an independent copy of the data object.

from_data(data)

Construct a frame from a data dict.

from_json(filepath)

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

from_jsonstring(string)

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

point(t)

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

to_data()

Convert an object to its native data representation.

to_json(filepath[, pretty])

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

to_jsonstring([pretty])

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

transform(T)

Transform this line.

transform_collection(collection, X)

Transform a collection of Line objects.

transformed(transformation)

Returns a transformed copy of this primitive.

transformed_collection(collection, X)

Create a collection of transformed Line objects.

validate_data()

Validate the object’s data against its data schema (self.DATASCHEMA).

validate_json()

Validate the object’s data against its json schema (self.JSONSCHEMA).

Attributes

DATASCHEMA

The schema of the data of this object.

JSONSCHEMA

The schema of the JSON representation of the data of this object.

data

The data dictionary that represents the line.

direction

A unit vector pointing from start and end.

dtype

The type of the object in the form of a “2-level” import and a class name.

end

The end point of the line.

guid

The globally unique identifier of the object.

length

The length of the vector from start to end.

midpoint

The midpoint between start and end.

name

The name of the object.

start

The start point of the line.

vector

A vector pointing from start to end.