#### Previous topic

17.7. The Maths Objects

#### Next topic

17.8. The NetworkDevice Object

# 17.7.1. The Vector2 Object¶

A Vector2 object represents a fixed length array with 2 single-precision floating point values. It behaves like a JavaScript array for getting or setting array elements but it can not be resized.

This object has been designed to provide optimal data storage for calculations done by the MathDevice.

## 17.7.1.1. Methods¶

### 17.7.1.1.1. slice¶

Summary

Create a new math object copying the contents from the current math object.

Syntax

```var vecCopy = vec.slice();
```

Returns a Vector2 object.

## 17.7.1.2. Properties¶

### 17.7.1.2.1. length¶

Summary

The number of elements on the math object, which for a Vector2 will be 2.

Syntax

```var numElements = vec.length;
```

Note

# 17.7.2. The Vector3 Object¶

A Vector3 object represents a fixed length array with 3 single-precision floating point values. It behaves like a JavaScript array for getting or setting array elements but it can not be resized.

This object has been designed to provide optimal data storage for calculations done by the MathDevice.

## 17.7.2.1. Methods¶

### 17.7.2.1.1. slice¶

Summary

Create a new math object copying the contents from the current math object.

Syntax

```var vecCopy = vec.slice();
```

Returns a Vector3 object.

## 17.7.2.2. Properties¶

### 17.7.2.2.1. length¶

Summary

The number of elements on the math object, which for a Vector3 will be 3.

Syntax

```var numElements = vec.length;
```

Note

# 17.7.3. The Vector4 Object¶

A Vector4 object represents a fixed length array with 4 single-precision floating point values. It behaves like a JavaScript array for getting or setting array elements but it can not be resized.

This object has been designed to provide optimal data storage for calculations done by the MathDevice.

Planes

Planes are represented with a Vector4 object. The first 3 components are the normal of the plane and the fourth component is its distance, in the direction of the normal, from the origin.

## 17.7.3.1. Methods¶

### 17.7.3.1.1. slice¶

Summary

Create a new math object copying the contents from the current math object.

Syntax

```var vecCopy = vec.slice();
```

Returns a Vector4 object.

## 17.7.3.2. Properties¶

### 17.7.3.2.1. length¶

Summary

The number of elements on the math object, which for a Vector4 will be 4.

Syntax

```var numElements = vec.length;
```

Note

# 17.7.4. The AABB (Axis Aligned Bounding Box) Object¶

A AABB object represents a fixed length array with 6 single-precision floating point values. It behaves like a JavaScript array for getting or setting array elements but it can not be resized.

The AABB object is represented internally as minimum and maximum points in 3D.

This object has been designed to provide optimal data storage for calculations done by the MathDevice.

## 17.7.4.1. Methods¶

### 17.7.4.1.1. slice¶

Summary

Create a new math object copying the contents from the current math object.

Syntax

```var aabbCopy = aabb.slice();
var aabbMin = aabb.slice(0, 3);
var aabbMax = aabb.slice(3, 6);
```

Returns a AABB object.

## 17.7.4.2. Properties¶

### 17.7.4.2.1. length¶

Summary

The number of elements on the math object, which for a AABB object will be 6.

Syntax

```var numElements = aabb.length;
```

Note

# 17.7.5. The Quaternion Object¶

A Quaternion object represents a rotation stored as a quaternion. It behaves like a JavaScript array for getting or setting array elements but it can not be resized.

This object has been designed to provide optimal data storage for calculations done by the MathDevice.

## 17.7.5.1. Methods¶

### 17.7.5.1.1. slice¶

Summary

Create a new math object copying the contents from the current math object.

Syntax

```var quatCopy = quat.slice();
```

Returns a Quaternion object.

## 17.7.5.2. Properties¶

### 17.7.5.2.1. length¶

Summary

The number of elements on the math object, which for a Quaternion will be 4.

Syntax

```var numElements = quat.length;
```

Note

# 17.7.6. The QuaternionPosition Object¶

A QuaternionPosition object represents a rotation stored as a quaternion and a position stored as 3 floating point values. It behaves like a JavaScript array for getting or setting array elements but it can not be resized. The quaternion is stored on the first 4 elements and the position on the last 3.

This object has been designed to provide optimal data storage for calculations done by the MathDevice.

## 17.7.6.1. Methods¶

### 17.7.6.1.1. slice¶

Summary

Create a new math object copying the contents from the current math object.

Syntax

```var quatPosCopy = quatPos.slice();
var quat = quatPos.slice(0, 4);
var pos = quatPos.slice(4, 7);
```

Returns a QuaternionPosition object.

## 17.7.6.2. Properties¶

### 17.7.6.2.1. length¶

Summary

The number of elements on the math object, which for a QuaternionPosition will be 7.

Syntax

```var numElements = quatPos.length;
```

Note

# 17.7.7. The Matrix33 Object¶

A Matrix33 object represents a 3 by 3 matrix stored as a fixed length array with 9 single-precision floating point values. It behaves like a JavaScript array for getting or setting array elements but it can not be resized.

This object has been designed to provide optimal data storage for calculations done by the MathDevice.

## 17.7.7.1. Methods¶

### 17.7.7.1.1. slice¶

Summary

Create a new math object copying the contents from the current math object.

Syntax

```var matrixCopy = matrix.slice();
var right = matrix.slice(0, 3);
var up    = matrix.slice(3, 6);
var at    = matrix.slice(6, 9);
```

The optional first parameter represents the offset of the element to start copying, valid values are multiples of 3.

The optional second parameter represents the offset of the element to end the copy, it is required to be the start offset plus 3.

Returns a Matrix33 object if no parameters are passed, a Vector3 otherwise.

## 17.7.7.2. Properties¶

### 17.7.7.2.1. length¶

Summary

The number of elements on the math object, which for a Matrix33 will be 9.

Syntax

```var numElements = matrix.length;
```

Note

# 17.7.8. The Matrix34 Object¶

A Matrix34 object represents a 3 by 4 matrix stored as a fixed length array with 12 single-precision floating point values. It behaves like a JavaScript array for getting or setting array elements but it can not be resized.

This object has been designed to provide optimal data storage for calculations done by the MathDevice.

## 17.7.8.1. Methods¶

### 17.7.8.1.1. slice¶

Summary

Create a new math object copying the contents from the current math object.

Syntax

```var matrixCopy = matrix.slice();
var vec0 = matrix.slice(0, 4);
var vec1 = matrix.slice(4, 8);
var vec2 = matrix.slice(8, 12);
```

The optional first parameter represents the offset of the element to start copying, valid values are multiples of 4.

The optional second parameter represents the offset of the element to end the copy, it is required to be the start offset plus 4.

Returns a Matrix34 object if no parameters are passed, a Vector4 otherwise.

## 17.7.8.2. Properties¶

### 17.7.8.2.1. length¶

Summary

The number of elements on the math object, which for a Matrix34 will be 12.

Syntax

```var numElements = matrix.length;
```

Note

# 17.7.9. The Matrix43 Object¶

A Matrix43 object represents a 4 by 3 matrix stored as a fixed length array with 12 single-precision floating point values. It behaves like a JavaScript array for getting or setting array elements but it can not be resized.

This object has been designed to provide optimal data storage for calculations done by the MathDevice.

## 17.7.9.1. Methods¶

### 17.7.9.1.1. slice¶

Summary

Create a new math object copying the contents from the current math object.

Syntax

```var matrixCopy = matrix.slice();
var right = matrix.slice(0, 3);
var up    = matrix.slice(3, 6);
var at    = matrix.slice(6, 9);
var pos   = matrix.slice(9, 12);
```

The optional first parameter represents the offset of the element to start copying, valid values are multiples of 3.

The optional second parameter represents the offset of the element to end the copy, it is required to be the start offset plus 3.

Returns a Matrix43 object if no parameters are passed, a Vector3 otherwise.

## 17.7.9.2. Properties¶

### 17.7.9.2.1. length¶

Summary

The number of elements on the math object, which for a Matrix43 will be 12.

Syntax

```var numElements = matrix.length;
```

Note

# 17.7.10. The Matrix44 Object¶

A Matrix44 object represents a 4 by 4 matrix stored as a fixed length array with 16 single-precision floating point values. It behaves like a JavaScript array for getting or setting array elements but it can not be resized.

This object has been designed to provide optimal data storage for calculations done by the MathDevice.

## 17.7.10.1. Methods¶

### 17.7.10.1.1. slice¶

Summary

Create a new math object copying the contents from the current math object.

Syntax

```var matrixCopy = matrix.slice();
var vec0 = matrix.slice(0, 4);
var vec1 = matrix.slice(4, 8);
var vec2 = matrix.slice(8, 12);
var vec3 = matrix.slice(12, 16);
```

The optional first parameter represents the offset of the element to start copying, valid values are multiples of 4.

The optional second parameter represents the offset of the element to end the copy, it is required to be the start offset plus 4.

Returns a Matrix44 object if no parameters are passed, a Vector4 otherwise.

## 17.7.10.2. Properties¶

### 17.7.10.2.1. length¶

Summary

The number of elements on the math object, which for a Matrix44 will be 16.

Syntax

```var numElements = matrix.length;
```

Note