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:61

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:

distanceSquared

(
  • p
)
Number

Get squared distance from this point to another point

Parameters:

Returns:

Number:

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

length

() Number

Get the length of the vector

Returns:

Number:

lengthSquared

() Number

Get the squared length of the vector.

Returns:

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

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

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

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

Vector addition

Parameters:

Returns:

Vec3:

vsub

(
  • v
  • target
)
Vec3

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