API Docs for: 6.0.1
Show:

Vector Class

Vector

Instantiation

  • scrawl.makeVector()

Purpose

  • To hold vector (coordinate, movement) data

Constructor

Vector

(
  • [items]
)

Parameters:

  • [items] Object optional

    Key:value Object argument for setting attributes

Methods

checkNotZero

()

Check to see if Vector is a zero vector

Returns:

True if Vector is non-zero; false otherwise

getCrossProduct

(
  • u
  • [v]
)
chainable

Obtain the cross product of one Vector and a copy of this, or another, Vector

Arithmetic is v(crossProduct)u, not u(crossProduct)v

Parameters:

  • u Object

    Vector to be used to calculate cross product; can also be an Object with x, y and z attributes (all optional)

  • [v] Vector optional

    Source vector (by default: this)

Returns:

New cross product Vector; this on failure

getData

()

extracts x and y data

Returns:

Object (not vector) with x and y attributes

getDotProduct

(
  • u
  • [v]
)

Obtain the dot product of one Vector and this, or another, Vector

Arithmetic is v(dotProduct)u, not u(dotProduct)v

Parameters:

  • u Object

    Vector to be used to calculate dot product; can also be an Object with x, y and z attributes (all optional)

  • [v] Vector optional

    Source vector (by default: this)

Returns:

Dot product result; false on failure

getMagnitude

()

Retrieve Vector's magnitude value

Returns:

Magnitude value

getTripleScalarProduct

(
  • u
  • v
  • [w]
)

Obtain the triple scalar product of two Vectors and this, or a third, Vector

Parameters:

  • u Object

    First vector to be used to calculate triple scalar product; can also be an Object with x, y and z attributes (all optional)

  • v Object

    Second vector to be used to calculate triple scalar product; can also be an Object with x, y and z attributes (all optional)

  • [w] Vector optional

    Third vector to be used to calculate triple scalar product (by default: this)

Returns:

Triple scalar product result; false on failure

getVector

()

Return a clone of this Vector

Returns:

Clone of this Vector

hasCoordinates

(
  • item
)

Check if x and y attributes are set

Parameters:

  • item Mixed

    Object to be tested

Returns:

True if argument possesses x and y attributes

isEqual

(
  • item
)

Compare two Vector objects for equality

Parameters:

  • item Mixed

    Object to be tested against this

Returns:

True if argument object is a Vector, and all attributes match; false otherwise

isLike

(
  • item
)

Comparea vector-like object to this one for equality

Parameters:

  • item Mixed

    Object to be tested against this

Returns:

True if all attributes match; false otherwise

normalize

() chainable

Normalize the Vector to a unit vector

Returns:

This

quaternionMultiply

(
  • item
  • [mag]
)
chainable

Rotate a Vector object by a Quaternion rotation

Parameters:

  • item Quaternion

    Quaternion object

  • [mag] Number optional

    Magnitude value to which Vector needs to be set after rotation

Returns:

Amended version of Vector; this on failure

reverse

() chainable

Rotate the Vector by 180 degrees

Returns:

This

rotate

(
  • angle
)
chainable

Rotate the Vector by a given angle

Parameters:

  • angle Number

    Rotation angle (in degrees)

Returns:

This

scalarDivide

(
  • item
)
chainable

Divide this Vector by a scalar value

Parameters:

  • item Number

    Division scalar

Returns:

This

scalarMultiply

(
  • item
)
chainable

Multiply this Vector by a scalar value

Parameters:

  • item Number

    Multiplier scalar

Returns:

This

set

(
  • items
)
chainable

Set attributes to new values

Parameters:

  • items Object

    Object containing attribute key:value pairs

Returns:

This

setMagnitudeTo

(
  • item
)
chainable

Set the Vector's coordinates to values that will result in the given magnitude

Parameters:

  • item Number

    New magnitude

Returns:

This

vectorAdd

(
  • item
)
chainable

Add a Vector to this Vector

Parameters:

  • item Object

    Vector to be added to this; can also be an Object with x, y and z attributes (all optional)

Returns:

This

vectorDivide

(
  • item
)
chainable

Divide a Vector into this Vector

Parameters:

  • item Object

    Vector to be divided into this; can also be an Object with x, y and z attributes (all optional)

Returns:

This

vectorMultiply

(
  • item
)
chainable

Multiply a Vector with this Vector

Parameters:

  • item Object

    Vector to be multiplied with this; can also be an Object with x, y and z attributes (all optional)

Returns:

This

vectorSubtract

(
  • item
)
chainable

Subtract a Vector from this Vector

Parameters:

  • item Object

    Vector to be subtracted from this; can also be an Object with x, y and z attributes (all optional)

Returns:

This

zero

() chainable

Set all attributes to zero

Returns:

This

Properties

name

String

Vector name - not guaranteed to be unique

Default: 'generic'

type

String final

Default: 'Vector'

x

Number

X coordinate (px)

Default: 0

y

Number

Y coodinate (px)

Default: 0

z

Number

Z coordinate (px)

Default: 0