#

API Docs for: 0.6.1
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
- distanceSquared
- distanceTo
- dot
- isAntiparallelTo
- isZero
- length
- lengthSquared
- lerp
- mult deprecated
- negate
- norm deprecated
- norm2 deprecated
- normalize
- scale
- set
- setZero
- tangents
- toArray
- toString
- unit
- vadd
- vsub

### Properties

- UNIT_X static
- UNIT_Y static
- UNIT_Z static
- x
- y
- z
- ZERO static

## Methods

### `almostEquals`

(

- `v`
- `precision`

)

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

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:414`

Check if a vector is almost zero

#### Parameters:

- `precision` Number

### `clone`

() Vec3

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

Clone the vector

#### Returns:

Vec3:

### `copy`

(

- `source`

)
Vec3

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

Copies value of source to this vector.

#### Parameters:

- `source` Vec3

#### Returns:

Vec3:

this

### `cross`

(

- `v`
- `target`

)
Vec3

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

Vector cross product

#### Parameters:

- `v` Vec3
- `target` Vec3

  Optional. Target to save in.

#### Returns:

Vec3:

### `crossmat`

() Mat3

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

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

#### Returns:

Mat3:

### `distanceSquared`

(

- `p`

)
Number

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

Get squared distance from this point to another point

#### Parameters:

- `p` Vec3

#### Returns:

Number:

### `distanceTo`

(

- `p`

)
Number

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

Get distance from this point to another point

#### Parameters:

- `p` Vec3

#### Returns:

Number:

### `dot`

(

- `v`

)
Number

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

Calculate dot product

#### Parameters:

- `v` Vec3

#### Returns:

Number:

### `isAntiparallelTo`

(

- `v`
- `precision`

)
Boolean

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

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:297`

#### Returns:

bool

### `length`

() Number

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

Get the length of the vector

#### Returns:

Number:

### `lengthSquared`

() Number

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

Get the squared length of the vector.

#### Returns:

Number:

### `lerp`

(

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

)

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

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:258`

Deprecated: Use .scale() instead

Multiply all the components of the vector with a scalar.

#### Parameters:

- `scalar` Number
- `target` Vec3

  The vector to save the result in.

#### Returns:

Vec3:

### `negate`

(

- `target`

)
Vec3

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

Make the vector point in the opposite direction.

#### Parameters:

- `target` Vec3

  Optional target to save in

#### Returns:

Vec3:

### `norm`

() Number deprecated

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

Deprecated: Use .length() instead

Get the length of the vector

#### Returns:

Number:

### `norm2`

() Number deprecated

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

Deprecated: Use .lengthSquared() instead.

Get the squared length of the vector

#### Returns:

Number:

### `normalize`

() Number

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

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:278`

Multiply the vector with a scalar.

#### Parameters:

- `scalar` Number
- `target` Vec3

#### Returns:

Vec3:

### `set`

(

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

)

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

Set the vectors' 3 elements

#### Parameters:

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

#### Returns:

Vec3

### `setZero`

()

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

Set all components of the vector to zero.

### `tangents`

(

- `t1`
- `t2`

)

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

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:358`

Converts to an array

#### Returns:

Array

### `toString`

()

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

Converts to a more readable format

#### Returns:

string

### `unit`

(

- `target`

)
Vec3

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

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:102`

Vector addition

#### Parameters:

- `v` Vec3
- `target` Vec3

  Optional.

#### Returns:

Vec3:

### `vsub`

(

- `v`
- `target`

)
Vec3

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

Vector subtraction

#### Parameters:

- `v` Vec3
- `target` Vec3

  Optional. Target to save in.

#### Returns:

Vec3:

## Properties

### `UNIT_X`

Vec3 static

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

### `UNIT_Y`

Vec3 static

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

### `UNIT_Z`

Vec3 static

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

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

### `ZERO`

Vec3 static

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