Vector

class compas.geometry.Vector(x, y, z=0.0, **kwargs)[source]

Bases: compas.geometry.primitives._primitive.Primitive

A vector is defined by XYZ components and a homogenisation factor.

Parameters
  • x (float) – The X component of the vector.

  • y (float) – The Y component of the vector.

  • z (float) – The Z component of the vector.

Attributes
  • data (dict) – The data representation of the vector.

  • x (float) – The component along the X axis of the vector.

  • y (float) – The component along the Y axis of the vector.

  • z (float) – The component along the Z axis of the vector.

  • length (float, read-only) – The length of the vector.

Examples

>>> u = Vector(1, 0, 0)
>>> v = Vector(0, 1, 0)
>>> u
Vector(1.000, 0.000, 0.000)
>>> v
Vector(0.000, 1.000, 0.000)
>>> u.x
1.0
>>> u[0]
1.0
>>> u.length
1.0
>>> u + v
Vector(1.000, 1.000, 0.000)
>>> u + [0.0, 1.0, 0.0]
Vector(1.000, 1.000, 0.000)
>>> u * 2
Vector(2.000, 0.000, 0.000)
>>> u.dot(v)
0.0
>>> u.cross(v)
Vector(0.000, 0.000, 1.000)

Methods

Xaxis()

Construct a unit vector along the X axis.

Yaxis()

Construct a unit vector along the Y axis.

Zaxis()

Construct a unit vector along the Z axis.

angle(other)

Compute the smallest angle between this vector and another vector.

angle_signed(other, normal)

Compute the signed angle between this vector and another vector.

angle_vectors(left, right)

Compute the smallest angle between corresponding pairs of two lists of vectors.

angles(other)

Compute both angles between this vector and another vector.

angles_vectors(left, right)

Compute both angles between corresponding pairs of two lists of vectors.

copy()

Make a copy of this vector.

cross(other)

The cross product of this vector and another vector.

cross_vectors(left, right)

Compute the cross product of two lists of vectors.

dot(other)

The dot product of this vector and another vector.

dot_vectors(left, right)

Compute the dot product of two lists of vectors.

from_data(data)

Construct a vector 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.

from_start_end(start, end)

Construct a vector from start and end points.

invert()

Invert the direction of this vector

inverted()

Returns a inverted copy of this vector

length_vectors(vectors)

Compute the length of multiple vectors.

scale(n)

Scale this vector by a factor n.

scaled(n)

Returns a scaled copy of this vector.

sum_vectors(vectors)

Compute the sum of multiple vectors.

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 vector.

transform_collection(collection, X)

Transform a collection of vector objects.

transformed(T)

Return a transformed copy of this vector.

transformed_collection(collection, X)

Create a collection of transformed vectors.

unitize()

Scale this vector to unit length.

unitized()

Returns a unitized copy of this vector.

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).