#

API Docs for: 0.6.0
Show: Inherited Protected Private Deprecated

# Vec3 Class

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

3-dimensional vector

## Constructor

### `Vec3`

(

- `x`
- `y`
- `z`

)

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

#### Parameters:

- `x` Number
- `y` Number
- `z` Number

#### Example:

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

- Index
- Methods
- Properties

## Item Index

### Methods

- almostEquals
- almostZero
- clone
- copy
- cross
- crossmat
- distanceTo
- dot
- isAntiparallelTo
- isZero
- lerp
- mult deprecated
- negate
- norm
- norm2
- normalize
- scale
- set
- setZero
- tangents
- toArray
- toString
- unit
- vadd
- vsub

### Properties

- x
- y
- z

## Methods

### `almostEquals`

(

- `v`
- `precision`

)

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

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

#### Parameters:

- `v` Vec3
- `precision` Number

#### Returns:

bool

### `almostZero`

(

- `precision`

)

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

Check if a vector is almost zero

#### Parameters:

- `precision` Number

### `clone`

() Vec3

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

Clone the vector

#### Returns:

Vec3:

### `copy`

(

- `source`

)
Vec3

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

Copies value of source to this vector.

#### Parameters:

- `source` Vec3

#### Returns:

Vec3:

this

### `cross`

(

- `v`
- `target`

)
Vec3

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

Vector cross product

#### Parameters:

- `v` Vec3
- `target` Vec3

  Optional. Target to save in.

#### Returns:

Vec3:

### `crossmat`

() Mat3

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

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

#### Returns:

Mat3:

### `distanceTo`

(

- `p`

)
Number

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

Get distance from this point to another point

#### Parameters:

- `p` Vec3

#### Returns:

Number:

### `dot`

(

- `v`

)
Number

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

Calculate dot product

#### Parameters:

- `v` Vec3

#### Returns:

Number:

### `isAntiparallelTo`

(

- `v`
- `precision`

)
Boolean

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

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

#### Parameters:

- `v` Vec3
- `precision` Number

  Set to zero for exact comparisons

#### Returns:

Boolean:

### `isZero`

()

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

#### Returns:

bool

### `lerp`

(

- `v`
- `t`
- `target`

)

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

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`

)
Vec3 deprecated

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

Deprecated: Use .scale instead

Multiply the vector with a scalar

#### Parameters:

- `scalar` Number
- `target` Vec3

#### Returns:

Vec3:

### `negate`

(

- `target`

)
Vec3

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

Make the vector point in the opposite direction.

#### Parameters:

- `target` Vec3

  Optional target to save in

#### Returns:

Vec3:

### `norm`

() Number

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

Get the 2-norm (length) of the vector

#### Returns:

Number:

### `norm2`

() Number

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

Get the squared length of the vector

#### Returns:

Number:

### `normalize`

() Number

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

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

#### Returns:

Number:

Returns the norm of the vector

### `scale`

(

- `scalar`
- `target`

)
Vec3

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

Multiply the vector with a scalar.

#### Parameters:

- `scalar` Number
- `target` Vec3

#### Returns:

Vec3:

### `set`

(

- `x`
- `y`
- `z`

)

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

Set the vectors' 3 elements

#### Parameters:

- `x` Number
- `y` Number
- `z` Number

#### Returns:

Vec3

### `setZero`

()

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

Set all components of the vector to zero.

### `tangents`

(

- `t1`
- `t2`

)

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

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`

()

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

Converts to an array

#### Returns:

Array

### `toString`

()

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

Converts to a more readable format

#### Returns:

string

### `unit`

(

- `target`

)
Vec3

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

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`

)
Vec3

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

Vector addition

#### Parameters:

- `v` Vec3
- `target` Vec3

  Optional.

#### Returns:

Vec3:

### `vsub`

(

- `v`
- `target`

)
Vec3

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

Vector subtraction

#### Parameters:

- `v` Vec3
- `target` Vec3

  Optional. Target to save in.

#### Returns:

Vec3:

## Properties

### `x`

Number

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

### `y`

Number

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

### `z`

Number

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