# API Docs for: 0.6.1
Show:

# Vec3 Class

3-dimensional vector

## Constructor

### `Vec3`

(
• `x`
• `y`
• `z`
)

#### Parameters:

• `x` Number
• `y` Number
• `z` Number

#### Example:

``````var v = new Vec3(1, 2, 3);
console.log('x=' + v.x); // x=1
``````

## Methods

### `almostEquals`

(
• `v`
• `precision`
)

Check if a vector equals is almost equal to another one.

#### Parameters:

• `v` Vec3
• `precision` Number

bool

### `almostZero`

(
• `precision`
)

Check if a vector is almost zero

#### Parameters:

• `precision` Number

()

Clone the vector

Vec3:

### `copy`

(
• `source`
)

Copies value of source to this vector.

#### Parameters:

• `source` Vec3

Vec3:

this

### `cross`

(
• `v`
• `target`
)

Vector cross product

#### Parameters:

• `v` Vec3
• `target` Vec3

Optional. Target to save in.

Vec3:

### `crossmat`

()

Get the cross product matrix a_cross from a vector, such that a x b = a_cross * b = c

Mat3:

### `distanceSquared`

(
• `p`
)
Number

Get squared distance from this point to another point

#### Parameters:

• `p` Vec3

Number:

### `distanceTo`

(
• `p`
)
Number

Get distance from this point to another point

#### Parameters:

• `p` Vec3

Number:

### `dot`

(
• `v`
)
Number

Calculate dot product

#### Parameters:

• `v` Vec3

Number:

### `isAntiparallelTo`

(
• `v`
• `precision`
)
Boolean

Check if the vector is anti-parallel to another vector.

#### Parameters:

• `v` Vec3
• `precision` Number

Set to zero for exact comparisons

Boolean:

()

bool

### `length`

() Number

Get the length of the vector

Number:

### `lengthSquared`

() Number

Get the squared length of the vector.

Number:

### `lerp`

(
• `v`
• `t`
• `target`
)

Do a linear interpolation between two vectors

#### Parameters:

• `v` Vec3
• `t` Number

A number between 0 and 1. 0 will make this function return u, and 1 will make it return v. Numbers in between will generate a vector in between them.

• `target` Vec3

### `mult`

(
• `scalar`
• `target`
)
deprecated

Defined in `src/math/Vec3.js:258`

Multiply all the components of the vector with a scalar.

#### Parameters:

• `scalar` Number
• `target` Vec3

The vector to save the result in.

Vec3:

### `negate`

(
• `target`
)

Make the vector point in the opposite direction.

#### Parameters:

• `target` Vec3

Optional target to save in

Vec3:

### `norm`

() Number deprecated

Defined in `src/math/Vec3.js:197`

Get the length of the vector

Number:

### `norm2`

() Number deprecated

Defined in `src/math/Vec3.js:215`

Get the squared length of the vector

Number:

### `normalize`

() Number

Normalize the vector. Note that this changes the values in the vector.

#### Returns:

Number:

Returns the norm of the vector

### `scale`

(
• `scalar`
• `target`
)

Multiply the vector with a scalar.

#### Parameters:

• `scalar` Number
• `target` Vec3

Vec3:

### `set`

(
• `x`
• `y`
• `z`
)

Set the vectors' 3 elements

#### Parameters:

• `x` Number
• `y` Number
• `z` Number

Vec3

### `setZero`

()

Set all components of the vector to zero.

### `tangents`

(
• `t1`
• `t2`
)

Compute two artificial tangents to the vector

#### Parameters:

• `t1` Vec3

Vector object to save the first tangent in

• `t2` Vec3

Vector object to save the second tangent in

### `toArray`

()

Converts to an array

Array

### `toString`

()

Converts to a more readable format

string

### `unit`

(
• `target`
)

Get the version of this vector that is of length 1.

#### Parameters:

• `target` Vec3

Optional target to save in

#### Returns:

Vec3:

Returns the unit vector

### `vadd`

(
• `v`
• `target`
)

#### Parameters:

• `v` Vec3
• `target` Vec3

Optional.

Vec3:

### `vsub`

(
• `v`
• `target`
)

Vector subtraction

#### Parameters:

• `v` Vec3
• `target` Vec3

Optional. Target to save in.

Vec3:

Vec3 static

Vec3 static

Vec3 static

Number

Number

Number

Vec3 static