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.
- 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.
Examples
>>> u = Vector(1, 0, 0) >>> v = Vector(0, 1, 0) >>> print(u) Vector(x=1.000, y=0.000, z=0.000) >>> print(v) Vector(x=0.000, y=1.000, z=0.000)
>>> u.x 1.0 >>> u[0] 1.0 >>> u.length 1.0
>>> result = u + v >>> print(result) Vector(x=1.000, y=1.000, z=0.000)
>>> result = u + [0.0, 1.0, 0.0] >>> print(result) Vector(x=1.000, y=1.000, z=0.000)
>>> result = u * 2 >>> print(result) Vector(x=2.000, y=0.000, z=0.000)
>>> u.dot(v) 0.0
>>> w = u.cross(v) >>> print(w) Vector(x=0.000, y=0.000, z=1.000)
Methods
Construct a unit vector along the X axis.
Construct a unit vector along the Y axis.
Construct a unit vector along the Z axis.
Compute the smallest angle between this vector and another vector.
Compute the signed angle between this vector and another vector.
Compute the smallest angle between corresponding pairs of two lists of vectors.
Compute both angles between this vector and another vector.
Compute both angles between corresponding pairs of two lists of vectors.
Compute the component of this vector in the direction of another vector.
Make a copy of this vector.
The cross product of this vector and another vector.
Compute the cross product of two lists of vectors.
The dot product of this vector and another vector.
Compute the dot product of two lists of vectors.
Construct a vector from start and end points.
Invert the direction of this vector
Returns a inverted copy of this vector
Compute the length of multiple vectors.
Scale this vector by a factor n.
Returns a scaled copy of this vector.
Compute the sum of multiple vectors.
Transform this vector.
Transform a collection of vector objects.
Return a transformed copy of this vector.
Create a collection of transformed vectors.
Scale this vector to unit length.
Returns a unitized copy of this vector.
Inherited Methods
Converts the instance to a string.
Compute the axis-aligned bounding box of the geometry.
Compute the oriented bounding box of the geometry.
Construct an object of this type from a JSON file.
Construct an object of this type from a JSON string.
Rotate the geometry.
Returns a rotated copy of this geometry.
Compute a hash of the data for comparison during version control using the sha256 algorithm.
Convert an object to its native data representation and save it to a JSON file.
Convert an object to its native data representation and save it to a JSON string.
Translate the geometry.
Returns a translated copy of this geometry.
Validate the data against the object's data schema.