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__(values=(0.0, 0.0, 0.0, 0.0))
```

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 `InvalidSize`

if `values`

is not 4 elements long, or `TypeError`

if `values`

is not a sequence of floats or ints.

```
__getitem__(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__(index, value)
```

This method lets you use square brackets to set a value on a vector.

```
setTo(sequence)
```

Set the contents of this vector to a sequence of floats.

Raises `InvalidSize`

if `values`

is not 4 elements long, or `TypeError`

if `values`

is not a sequence of floats or ints.

```
__len__()
```

→ int

Returns 4. This method lets you call len() on a Vector4.

```
__add__(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`

, where `v1`

and `v2`

are
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__(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`

,
where `v1`

and `v2`

are 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__(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 * s`

or `v * m`

where `v`

is a vector, `s`

is
a float scalar, and `m`

is a hou.Matrix4.

See hou.Vector3.__mul__() for more information.

```
__rmul__(scalar)
```

→ hou.Vector4

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.Vector4.__mul__(), which lets you write `v * s`

.

>>> v = hou.Vector4(1, 2, 3, 4) >>> v * 2 <hou.Vector4 [2, 4, 6, 8]> >>> 2 * v <hou.Vector4 [2, 4, 6, 8]>

```
__div__(scalar)
```

→ hou.Vector4

Divide a vector by a float scalar, returning a new vector. This method
lets you write `v / s`

where `v`

is a vector and `s`

is a float.

This method is equivalent to
`hou.Vector4(self[0] / scalar, self[1] / scalar, self[2] / scalar, self[3] / scalar)`

.

```
length()
```

→ 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()
```

→ float

Return the result of `self.length()**2`

. The result is the same as
`self[0]**2 + self[1]**2 + self[2]**2 + self[3]**2`

.

```
normalized()
```

→ 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(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(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.

```
ocio_transform(src_space, dest_space)
```

→ hou.Vector4

Use Open Color IO to transform the color from the source space to the destination space.

```
x()
```

→ ```
float
```

Return the first component of the vector. Equivalent to v/hom/hou/0.

```
y()
```

→ ```
float
```

Return the second component of the vector. Equivalent to v/hom/hou/1.

```
z()
```

→ ```
float
```

Return the third component of the vector. Equivalent to v/hom/hou/2.

```
w()
```

→ ```
float
```

Return the fourth component of the vector. Equivalent to v/hom/hou/3.