A sequence of 3 floating point values, with associated mathematical operations.
A Vector3 might be used to represent a position in 3D space, or a 3D direction with a length.
See also hou.Vector2 and hou.Vector4.
Methods
| __add__ | Add two vectors, returning a new vector with each component equal to the sum of the corresponding components in the two vectors. This method lets you write v1 + v2, where v1 and v2 are Vector3 objects. |
| __getitem__ | 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. |
| __init__ | Return a new Vector3 from a sequence of floats. If this method is called without parameters, the resulting vector contains the values (0.0, 0.0, 0.0). |
| __len__ | Returns 3. This method lets you call len() on a Vector3. |
| __mul__ | Multiply this vector with a scalar or with a matrix, returning a new vector. This method lets you write v * s or v * m where v is a vector, s is a float scalar, and m is a hou.Matrix4. |
| __neg__ | Return a vector whose components contain the negative values of this vector’s components. This method lets you write -v, where v is a Vector3 object. |
| __rmul__ | Multiply this vector with a scalar, returning a new vector. This method lets you write s * v, where v is a vector and s is a float scalar. See also hou.Vector3.__mul__, which lets you write v * s. |
| __setitem__ | This method lets you use square brackets to set a value on a vector. |
| __sub__ | Subtract a vector from another, returning a new vector with each component equal to the first vector’s corresponding component minus the second vector's. This method lets you write v1 - v2, where v1 and v2 are Vector3 objects. |
| angleTo | Interprets this Vector3 and the parameter as directions and returns the angle (in degrees) formed between the two vectors when you place the origins at the same location. |
| cross | Return the cross product of this vector with another vector. The return value is a vector that is perpendicular to both vectors, pointing in the direction defined by the right-hand rule, with length self.length() * vector3.length() * math.sin(hou.hmath.degToRad(self.angleTo(vector3))). |
| distanceTo | Interpret this vector and the argument as 3D positions, and return the distance between them. The return value is equivalent to (self - vector3).length(). |
| dot | Return the dot product between this vector and the one in the parameter. This value is equal to self[0]*vector3[0] + self[1]*vector3[1] + self[2]*vector3[2], which is also equal to self.length() * vector3.length() * math.cos(hou.hmath.degToRad(self.angleTo(vector3))) |
| isAlmostEqual | 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. |
| length | Interpret this vector as a direction vector and return its length. The result is the same as math.sqrt(self[0]**2 + self[1]**2 + self[2]**2). |
| lengthSquared | Interpret this vector as a direction vector and return the square of its length. The result is the same as self[0]**2 + self[1]**2 + self[2]**2. |
| matrixToRotateTo | Return a matrix that rotates this vector onto vector3, rotating about the axis perpendicular to the two vectors. If the two vectors have the same direction, return the identity matrix. |
| normalized | Interpret this vector as a direction and return a vector with the same direction but with a length of 1. |
| setTo | Set the contents of this vector to a sequence of floats. |
__init__(self, values=(0.0, 0.0, 0.0))Return a new Vector3 from a sequence of floats. If this method is called without parameters, the resulting vector contains the values (0.0, 0.0, 0.0).
You can also construct a Vector3 from a hou.Vector4. The result contains the first 3 values in the Vector4.
Raises
InvalidSizeifvaluesis not 3 elements long, orTypeErrorifvaluesis not a sequence of floats.__getitem__(self, index)→floatReturn 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.
>>> v = hou.Vector3((1.0, 2.0, 3.0)) >>> v[-1] 3.0
__setitem__(self, index, value)This method lets you use square brackets to set a value on a vector.
>>> v = hou.Vector3((1.5, 2.5, 3.5)) >>> v[1] = 0.5 >>> print v [1.5, 0.5, 3.5]
setTo(self, sequence)Set the contents of this vector to a sequence of floats.
Raises
InvalidSizeifvaluesis not 3 elements long, orTypeErrorifvaluesis not a sequence of floats or ints.__len__(self)→intReturns 3. This method lets you call len() on a Vector3.
__add__(self, vector3)→ hou.Vector3Add two vectors, returning a new vector with each component equal to the sum of the corresponding components in the two vectors. This method lets you write
v1 + v2, wherev1andv2are Vector3 objects.This method is equivalent to
hou.Vector3(self[0] + vector3[0], self[1] + vector3[1], self[2] + vector3[2]).__sub__(self, vector3)→ hou.Vector3Subtract a vector from another, returning a new vector with each component equal to the first vector’s corresponding component minus the second vector's. This method lets you write
v1 - v2, wherev1andv2are Vector3 objects.This method is equivalent to
hou.Vector3(self[0] - vector3[0], self[1] - vector3[1], self[2] - vector3[2]).__neg__(self)→ hou.Vector3Return a vector whose components contain the negative values of this vector’s components. This method lets you write
-v, wherevis a Vector3 object.This method is equivalent to
hou.Vector3(-self[0], -self[1], -self[2]).__mul__(self, scalar_or_matrix4)→ hou.Vector3Multiply this 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.When the parameter is a float scalar
s, this method is equivalent tohou.Vector3(self[0] * s, self[1] * s, self[2] * s).In order multiply the Vector3 by a Matrix4, the Vector3 is converted to a Vector4 with the fourth component set to 1.0. The effect is that the vector is treated as a position, so if the transformation matrix contains a translation component, the return value will be translated. If you would like to transform a vector (so translations are ignored but rotations, for example, apply), you’ll need to transform a corresponding hou.Vector4 with the fourth component set to zero:
# Build a transformation matrix that rotates 180 degrees about z and then translates by 1 in x. >>> matrix = hou.hmath.buildRotateAboutAxis((0, 0, 1), 180) * hou.hmath.buildTranslate((1, 0, 0)) >>> position = hou.Vector3(0.0, 1.0, 0.0) # Rotate the point (0,1,0) to (0,-1,0), then translate to (1,-1,0). >>> position * matrix <hou.Vector3 [1, -1, 0]> # Rotate the vector (0,1,0) to (0,-1,0), ignoring the translation. >>> vector = hou.Vector4(tuple(position) + (0.0,)) >>> vector <hou.Vector4 [0, 1, 0, 0]> >>> vector * matrix <hou.Vector4 [0, -1, 0, 0]> >>> hou.Vector3(vector * matrix) <hou.Vector3 [0, -1, 0]> # We could have wrapped the above in a function: >>> def transformAsVector(vector3): ... return hou.Vector3(hou.Vector4(tuple(vector3) + (0.0,)) * matrix) >>> transformAsVector(position) <hou.Vector3 [0, -1, 0]> # Change the Vector4's last component to 1 to illustrate that it's transformed as a point again. >>> vector[-1] = 1.0 >>> vector <hou.Vector4 [0, 1, 0, 1]> >>> vector * matrix <hou.Vector4 [1, -1, 0, 1]>
See also hou.Matrix4.
__rmul__(self, scalar)→ hou.Vector3Multiply 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.Vector3.__mul__, which lets you writev * s.>>> v = hou.Vector3(1, 2, 3) >>> v * 2 <hou.Vector3 [2, 4, 6]> >>> 2 * v <hou.Vector3 [2, 4, 6]>
length(self)→floatInterpret this vector as a direction vector and return its length. The result is the same as
math.sqrt(self[0]**2 + self[1]**2 + self[2]**2).lengthSquared(self)→floatInterpret this vector as a direction vector and return the square of its length. The result is the same as
self[0]**2 + self[1]**2 + self[2]**2.normalized(self)→ hou.Vector3Interpret this vector as a direction and return a vector with the same direction but with a length of 1.
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()).distanceTo(self, vector3)→floatInterpret this vector and the argument as 3D positions, and return the distance between them. The return value is equivalent to
(self - vector3).length().dot(self, vector3)→floatReturn the dot product between this vector and the one in the parameter. This value is equal to
self[0]*vector3[0] + self[1]*vector3[1] + self[2]*vector3[2], which is also equal toself.length() * vector3.length() * math.cos(hou.hmath.degToRad(self.angleTo(vector3)))cross(self, vector3)→ hou.Vector3Return the cross product of this vector with another vector. The return value is a vector that is perpendicular to both vectors, pointing in the direction defined by the right-hand rule, with length
self.length() * vector3.length() * math.sin(hou.hmath.degToRad(self.angleTo(vector3))).angleTo(self, vector3)→floatInterprets this Vector3 and the parameter as directions and returns the angle (in degrees) formed between the two vectors when you place the origins at the same location.
angularVelocityTo(self, vector3, time_interval)This feature is not yet implemented
clampLengthAsNew(self, min_length, max_length)→ hou.Vector3This feature is not yet implemented
matrixToRotateTo(self, vector3)→ hou.Matrix4Return a matrix that rotates this vector onto
vector3, rotating about the axis perpendicular to the two vectors. If the two vectors have the same direction, return the identity matrix.isAlmostEqual(self, vector3, tolerance=0.00001)→boolReturn 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.