API Docs for: 0.6.1
Show:

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

Methods

almostEquals

(
  • v
  • precision
)

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

Parameters:

  • v Vec3
  • precision Number

Returns:

bool

almostZero

(
  • precision
)

Check if a vector is almost zero

Parameters:

  • precision Number

clone

() Vec3

Clone the vector

Returns:

Vec3:

copy

(
  • source
)
Vec3

Copies value of source to this vector.

Parameters:

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

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

Returns:

Mat3:

distanceTo

(
  • p
)
Number

Get distance from this point to another point

Parameters:

Returns:

Number:

dot

(
  • v
)
Number

Calculate dot product

Parameters:

Returns:

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

Returns:

Boolean:

isZero

()

Returns:

bool

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
)
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

Make the vector point in the opposite direction.

Parameters:

  • target Vec3

    Optional target to save in

Returns:

Vec3:

norm

() Number

Get the 2-norm (length) of the vector

Returns:

Number:

norm2

() Number

Get the squared length of the vector

Returns:

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
)
Vec3

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
)

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

Returns:

Array

toString

()

Converts to a more readable format

Returns:

string

unit

(
  • target
)
Vec3

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:

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