Vector

class compas.geometry.Vector[source]

Bases: Geometry

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

Parameters:
xfloat

The X component of the vector.

yfloat

The Y component of the vector.

zfloat

The Z component of the vector.

namestr, optional

The name 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)
Attributes:
xfloat

The X coordinate of the point.

yfloat

The Y coordinate of the point.

zfloat

The Z coordinate of the point.

lengthfloat, read-only

The length of this vector.

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

Compute the smallest angle between this vector and another vector.

angle_signed

Compute the signed angle between this vector and another vector.

angle_vectors

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

angles

Compute both angles between this vector and another vector.

angles_vectors

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

component

Compute the component of this vector in the direction of another vector.

copy

Make a copy of this vector.

cross

The cross product of this vector and another vector.

cross_vectors

Compute the cross product of two lists of vectors.

dot

The dot product of this vector and another vector.

dot_vectors

Compute the dot product of two lists of vectors.

from_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

Compute the length of multiple vectors.

scale

Scale this vector by a factor n.

scaled

Returns a scaled copy of this vector.

sum_vectors

Compute the sum of multiple vectors.

transform

Transform this vector.

transform_collection

Transform a collection of vector objects.

transformed

Return a transformed copy of this vector.

transformed_collection

Create a collection of transformed vectors.

unitize

Scale this vector to unit length.

unitized

Returns a unitized copy of this vector.

Inherited Methods

ToString

Converts the instance to a string.

compute_aabb

Compute the axis-aligned bounding box of the geometry.

compute_obb

Compute the oriented bounding box of the geometry.

from_json

Construct an object of this type from a JSON file.

from_jsonstring

Construct an object of this type from a JSON string.

rotate

Rotate the geometry.

rotated

Returns a rotated copy of this geometry.

sha256

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

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.

translate

Translate the geometry.

translated

Returns a translated copy of this geometry.

validate_data

Validate the data against the object's data schema.