hou.Vector4
class
A sequence of 4 floating point values, with associated mathematical operations.
A Vector4 could be used to represent a position or direction in 4D space. In 3D math, however, it is more commonly used to represent either a position or a vector, depending on the value of the fourth component. Positions have a fourth component of 1.0, and vectors have a fourth component of 0.0. Subtracting a position from another yields a vector, adding two vectors together yields a vector, and adding a point and a vector yields a point. Operations that yield a fourth component value other than 0 or 1, like adding two points together, are not valid. Similarly, is makes sense to speak about a vector’s length but not a position’s length. The fourth component also affects how the position/vector is transformed; see hou.Vector3.__mul__ for more information.
See also hou.Vector2 and hou.Vector3.
Methods
__init__(self, values)-
Return a new Vector4 from a sequence of floats. If this method is called without parameters, the resulting vector contains the values (0.0, 0.0, 0.0, 0.0).
You can also construct a Vector4 from a hou.Vector3. The new vector has its fourth component set to 1.0.
Raises
InvalidSizeifvaluesis not 4 elements long, orTypeErrorifvaluesis not a sequence of floats or ints. __getitem__(self, index)→float-
Return the float component at the specified index. This method makes vectors behave as sequences (so you can, for example, use a for loop on the elements of a vector, convert a vector to a tuple of floats, etc.) and lets you use square brackets to index into a vector.
__setitem__(self, index, value)-
This method lets you use square brackets to set a value on a vector.
setTo(self, sequence)-
Set the contents of this vector to a sequence of floats.
Raises
InvalidSizeifvaluesis not 4 elements long, orTypeErrorifvaluesis not a sequence of floats or ints. __len__(self)→ int-
Returns 4. This method lets you call len() on a Vector4.
__add__(self, vector4)→ hou.Vector4-
Add two vectors, returning a new vector with each component (including the last one) equal to the sum of the corresponding components in the two vectors. This method lets you write
v1 + v2, wherev1andv2are Vector4 objects.This method is equivalent to
hou.Vector4(self[0] + vector4[0], self[1] + vector4[1], self[2] + vector4[2], self[3] + vector4[3]). __sub__(self, vector4)→ hou.Vector4-
Subtract a vector from another, returning a new vector with each component (including the last one) equal to the first vector’s corresponding component minus the second vector’s. This method lets you write
v1 - v2, wherev1andv2are Vector4 objects.This method is equivalent to
hou.Vector4(self[0] - vector4[0], self[1] - vector4[1], self[2] - vector4[2], self[3] - vector4[3]). __mul__(self, scalar_or_matrix4)→ hou.Vector4-
Multiply a vector with a scalar or with a matrix, returning a new vector. This method lets you write
v * sorv * mwherevis a vector,sis a float scalar, andmis a hou.Matrix4.See hou.Vector3.__mul__ for more information.
__rmul__(self, scalar)→ hou.Vector4-
Multiply this vector with a scalar, returning a new vector. This method lets you write
s * v, wherevis a vector andsis a float scalar. See also hou.Vector4.__mul__, which lets you writev * s.>>> v = hou.Vector4(1, 2, 3, 4) >>> v * 2 <hou.Vector3 [2, 4, 6, 8]> >>> 2 * v <hou.Vector3 [2, 4, 6, 8]>
length(self)→ float-
Interpret this vector as a 4D direction vector and return its length. If this vector is representing a 3D direction (so the fourth component is 0), the result is the 3D length.
The result is the same as
math.sqrt(self[0]**2 + self[1]**2 + self[2]**2 + self[3]**2). lengthSquared(self)→ float-
Return the result of
self.length()**2. The result is the same asself[0]**2 + self[1]**2 + self[2]**2 + self[3]**2. normalized(self)→ Vector4-
Interpret this vector as a 4D direction and return a vector with the same direction but with a length of 1. If this vector being used to represent a 3D direction (so the fourth component is 0), the result is still meaningful, and represents the corresponding 3D direction.
If the vector’s length is 0 (or close to it), the result is the original vector.
For vectors with non-zero lengths, this method is equivalent to
self * (1.0/self.length()). dot(self, vector4)→ float-
Return the dot product between this 4D vector and the one in the parameter. This value is equal to
self[0]*vector4[0] + self[1]*vector4[1] + self[2]*vector4[2] + self[3]*vector4[3]. isAlmostEqual(self, vector4, tolerance=0.00001)→bool-
Return whether this vector is equal to another, within a tolerance. Verifies that the difference between each component of this vector and the corresponding component of the other vector is within the tolerance.