API Documentation for: 0.11.8
Show:

platypus.Vector Class

Defined in: platypus.Vector:1
Module: platypus

This class defines a multi-dimensional vector object and a variety of methods for manipulating the vector.

Constructor

platypus.Vector

(
  • x
  • [y]
  • [z]
)

Defined in platypus.Vector:1

Parameters:

  • x Number | Array | Vector

    The x coordinate or an array or Vector describing the whole vector.

  • [y] Number optional

    The y coordinate.

  • [z] Number optional

    The z coordinate.

Methods

add

(
  • x
  • [y]
  • [z]
)
chainable

Defined in add:388

Adds the given components to this vector.

Parameters:

  • x Number | Array | Vector

    The x component to add, or an array or vector describing the whole addition.

  • [y] Number optional

    The y component to add or the limit if the first parameter is a vector or array.

  • [z] Number optional

    The z component to add.

addVector

(
  • otherVector
)
chainable

Defined in addVector:421

Adds the given vector to this vector.

Parameters:

angleTo

(
  • otherVector
)
Number

Defined in angleTo:478

Finds the shortest angle between the two vectors.

Parameters:

Returns:

Number:

The angle between this vector and the received vector.

copy

() platypus.Vector

Defined in copy:551

Returns a copy of this vector.

Returns:

platypus.Vector:

A copy of this vector.

cross

(
  • vector
)
chainable

Defined in cross:269

Crosses this vector with the parameter vector.

Parameters:

dot

(
  • otherVector
  • limit
)
Number

Defined in dot:455

Finds the dot product of the two vectors.

Parameters:

  • otherVector platypus.Vector

    The other vector.

  • limit Number

    The number of vector indexes to include in the dot product.

Returns:

Number:

The dot product.

equals

(
  • x
  • [y]
  • [z]
)
Boolean

Defined in equals:157

Available since 0.7.3

Determines whether two vectors are equal.

Parameters:

  • x Number | Array | Vector

    The x coordinate or an array or Vector to check against.

  • [y] Number optional

    The y coordinate, or if x is an array/Vector this is the number of dimensions to check from the array/Vector.

  • [z] Number optional

    The z coordinate.

Returns:

Boolean:

Whether the vectors are equal.

getCrossProduct

(
  • vector
)
platypus.Vector

Defined in getCrossProduct:294

Crosses this vector with the parameter vector and returns the cross product.

Parameters:

Returns:

platypus.Vector:

The cross product.

getInverse

() platypus.Vector

Defined in getInverse:242

Returns a copy of the Vector inverted.

Returns:

getUnit

() platypus.Vector

Defined in getUnit:232

Returns a normalized copy of the vector.

Returns:

platypus.Vector:

A normalized vector in the same direction as this vector.

magnitude

(
  • [dimensions]
)
Number

Defined in magnitude:194

Returns the magnitude of the vector.

Parameters:

  • [dimensions] Number optional

    The dimensions to include. Defaults to all dimensions.

Returns:

Number:

The magnitude of the vector.

multiply

(
  • factor
  • limit
)
chainable

Defined in multiply:443

Scales the vector by the given factor.

Parameters:

  • factor Number

    The factor to scale by.

  • limit Number

    Determines which coordinates are affected. Defaults to all coordinates.

multiply

(
  • multiplier
  • limit
)
chainable

Defined in multiply:354

Scales the vector by the given factor or performs a transform if a matrix is provided.

Parameters:

  • multiplier Number | Array

    The factor to scale by or a 2D array describing a multiplication matrix.

  • limit Number

    For scaling, determines which coordinates are affected.

normalize

() chainable

Defined in normalize:252

Normalizes the vector.

recycle

()

Defined in recycle:633

Available since 0.7.1

Relinquishes properties of the vector and recycles it.

rotate

(
  • angle
  • [axis="z"]
)
chainable

Defined in rotate:305

Rotates the vector by the given amount.

Parameters:

  • angle Number

    The amount to rotate the vector in radians.

  • [axis="z"] String | Vector optional

    A vector describing the axis around which the rotation should occur or 'x', 'y', or 'z'.

scalerProjection

(
  • vectorOrAngle
)
Number

Find the scalar value of projecting this vector onto the parameter vector or onto a vector at the specified angle away.

Parameters:

  • vectorOrAngle Vector | Number

    The other vector or the angle between the vectors.

Returns:

Number:

The magnitude of the projection.

set

(
  • x
  • [y]
  • [z]
)
chainable

Defined in set:85

Sets the coordinates of the vector.

Parameters:

  • x Number | Array | Vector

    The x coordinate or an array or Vector describing the whole vector.

  • [y] Number optional

    The y coordinate, or if x is an array/Vector this is the number of elements to copy from the array/Vector.

  • [z] Number optional

    The z coordinate.

setArray

(
  • arr
  • [dimensions]
)
chainable

Defined in setArray:137

Available since 0.7.4

Sets the coordinates of the vector.

Parameters:

  • arr Array

    The array to copy.

  • [dimensions] Number optional

    The number of elements to copy from the Array.

setVector

(
  • vector
  • [dimensions]
)
chainable

Defined in setVector:124

Available since 0.7.4

Sets the coordinates of the vector.

Parameters:

  • vector Vector

    The Vector to copy.

  • [dimensions] Number optional

    The number of elements to copy from the Vector.

setXYZ

(
  • x
  • [y]
  • [z]
)
chainable

Defined in setXYZ:104

Available since 0.7.4

Sets the coordinates of the vector.

Parameters:

  • x Number

    The x coordinate.

  • [y] Number optional

    The y coordinate.

  • [z] Number optional

    The z coordinate.

signedAngleTo

(
  • otherVector
  • normal
)
Number

Defined in signedAngleTo:503

Finds the shortest signed angle between the two vectors.

Parameters:

  • otherVector platypus.Vector

    The other vector.

  • normal platypus.Vector

    A normal vector determining the resultant sign of the angle between two vectors.

Returns:

Number:

The angle between this vector and the received vector.

subtractVector

(
  • otherVector
)
chainable

Defined in subtractVector:432

Subtracts the given vector from this vector.

Parameters:

toString

() String

Defined in toString:75

Returns a string describing the vector in the format of "[x, y, z]".

Returns:

Vector.assign

(
  • object
  • propertyName
  • [coordinateName*]
)

Defined in Vector.assign:561

Adds properties to an object that describe the coordinates of a vector.

Parameters:

  • object Object

    Object on which the coordinates and vector will be added.

  • propertyName String

    A string describing the property name where the vector is accessable.

  • [coordinateName*] String optional

    One or more parameters describing coordinate values on the object.

Vector.recycle

(
  • The
)

Defined in Vector.recycle:626

Available since 0.7.1

Returns a Vector back to the cache. Prefer the Vector's recycle method since it recycles property objects as well.

Parameters:

Vector.setUp

() platypus.Vector

Defined in Vector.setUp:619

Available since 0.7.1

Returns a Vector from cache or creates a new one if none are available.

Returns:

platypus.Vector:

The instantiated Vector.

Properties

x

Number

Defined in x:27

The x component of the vector.

Default: 0

y

Number

Defined in y:43

The y component of the vector.

Default: 0

z

Number

Defined in z:59

The z component of the vector.

Default: 0