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
data (dict) – The data representation of the line.
start (
compas.geometry.Point
) – The first point of the line.end (
compas.geometry.Point
) – The second point of the line.vector (
compas.geometry.Vector
) – A vector pointing fromstart
toend
.direction (
compas.geometry.Vector
) – A unit vector pointing fromstart
toend
.midpoint (
compas.geometry.Point
) – A point half way betweenstart
andend
.length (float, read-only) – The length of the line segment between
start
andend
.
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.midpoint Point(0.500, 0.500, 0.500) >>> line.length == sqrt(1 + 1 + 1) True >>> line.direction Vector(0.577, 0.577, 0.577)
>>> type(line.start) == Point True >>> type(line.midpoint) == Point True >>> type(line.direction) == Vector True
Methods
from_data
(data)Construct a frame from a data dict.
point
(t)A point between start and end at a specific normalized parameter.
transform
(T)Transform this line.
transform_collection
(collection, X)Transform a collection of
Line
objects.transformed_collection
(collection, X)Create a collection of transformed
Line
objects.Inherited Methods
copy
()Makes a copy of this primitive.
from_json
(filepath)Construct a primitive from structured data contained in a json file.
to_data
()Returns the data dictionary that represents the primitive.
to_json
(filepath)Serialise the structured data representing the primitive to json.
transformed
(transformation)Returns a transformed copy of this primitive.
Validate the data of this object against its data schema (self.DATASCHEMA).
Validate the data loaded from a JSON representation of the data of this object against its data schema (self.DATASCHEMA).