API Docs for: 0.3
Show:

2 Dimensional Vector Class

Module: CrowdSim

Methods

add

(
  • out
  • a
  • b
)

Adds two vec2's

Parameters:

  • out Vec2

    the receiving vector

  • a Vec2

    the first operand

  • b Vec2

    the second operand

Returns:

out

add3

(
  • out
  • a
  • b
  • c
)

Adds three vec2's

Parameters:

  • out Vec2

    the receiving vector

  • a Vec2

    the first operand

  • b Vec2

    the second operand

  • c Vec2

    the third operand

Returns:

out

clone

(
  • a
)

Creates a new vec2 initialized with values from an existing vector

Parameters:

  • a Vec2

    vector to clone

Returns:

out

copy

(
  • out
  • a
)

Copy the values from one vec2 to another

Parameters:

  • out Vec2

    the receiving vector

  • a Vec2

    the source vector

Returns:

out

create

()

Creates a new, empty vec2

Returns:

out

cross

(
  • out
  • a
  • b
)

Computes the cross product of two vec2's Note that the cross product must by definition produce a 3D vector

Parameters:

  • out Vec3

    the receiving vector

  • a Vec2

    the first operand

  • b Vec2

    the second operand

Returns:

out

distance

(
  • a
  • b
)

Calculates the euclidian distance between two vec2's

Parameters:

  • a Vec2

    the first operand

  • b Vec2

    the second operand

Returns:

CallExpression

divide

(
  • out
  • a
  • b
)

Divides two vec2's

Parameters:

  • out Vec2

    the receiving vector

  • a Vec2

    the first operand

  • b Vec2

    the second operand

Returns:

out

dot

(
  • a
  • b
)

Calculates the dot product of two vec2's

Parameters:

  • a Vec2

    the first operand

  • b Vec2

    the second operand

Returns:

BinaryExpression

fromValues

(
  • x
  • y
)

Creates a new vec2 initialized with the given values

Parameters:

Returns:

out

inverse

(
  • out
  • a
)

Returns the inverse of the components of a vec2

Parameters:

  • out Vec2

    the receiving vector

  • a Vec2

    vector to invert

Returns:

out

()

Alias for {@link vec2.divide}

()

Alias for {@link vec2.subtract}

length

(
  • a
)

Calculates the length of a vec2

Parameters:

  • a Vec2

    vector to calculate length of

Returns:

CallExpression

()

Alias for {@link vec2.squaredLength}

()

Alias for {@link vec2.length}

()

Alias for {@link vec2.multiply}

()

Alias for {@link vec2.distance}

(
  • a
  • stride
  • offset
  • count
  • fn
  • [arg]
)
Array

Perform some operation over an array of vec2s.

Parameters:

  • a Array

    the array of vectors to iterate over

  • stride Number

    Number of elements between the start of each vec2. If 0 assumes tightly packed

  • offset Number

    Number of elements to skip at the beginning of the array

  • count Number

    Number of vec2s to iterate over. If 0 iterates over entire array

  • fn Function

    Function to call for each vector in the array

  • [arg] Object optional

    additional argument to pass to fn

Returns:

Array:

a

()

Alias for {@link vec2.squaredDistance}

lerp

(
  • out
  • a
  • b
  • t
)

Performs a linear interpolation between two vec2's

Parameters:

  • out Vec2

    the receiving vector

  • a Vec2

    the first operand

  • b Vec2

    the second operand

  • t Number

    interpolation amount between the two inputs

Returns:

out

max

(
  • out
  • a
  • b
)

Returns the maximum of two vec2's

Parameters:

  • out Vec2

    the receiving vector

  • a Vec2

    the first operand

  • b Vec2

    the second operand

Returns:

out

min

(
  • out
  • a
  • b
)

Returns the minimum of two vec2's

Parameters:

  • out Vec2

    the receiving vector

  • a Vec2

    the first operand

  • b Vec2

    the second operand

Returns:

out

multiply

(
  • out
  • a
  • b
)

Multiplies two vec2's

Parameters:

  • out Vec2

    the receiving vector

  • a Vec2

    the first operand

  • b Vec2

    the second operand

Returns:

out

negate

(
  • out
  • a
)

Negates the components of a vec2

Parameters:

  • out Vec2

    the receiving vector

  • a Vec2

    vector to negate

Returns:

out

normalize

(
  • out
  • a
)

Normalize a vec2

Parameters:

  • out Vec2

    the receiving vector

  • a Vec2

    vector to normalize

Returns:

out

normalizeAndScale

(
  • out
  • a
  • b
)

Normalize a vec2

Parameters:

  • out Vec2

    the receiving vector

  • a Vec2

    vector to normalize

  • b Object

Returns:

out

projectionToSegment

(
  • out
  • p
  • a
  • b
)

Calculates the shortest projection between a point and a line defined by two vec2's

Parameters:

  • out Object
  • p Vec2

    the point

  • a Vec2

    the first operand

  • b Vec2

    the second operand

Returns:

CallExpression

random

(
  • out
  • scale
)

Generates a random vector with the given scale

Parameters:

  • out Vec2

    the receiving vector

  • scale Object

Returns:

out

scale

(
  • out
  • a
  • b
)

Scales a vec2 by a scalar number

Parameters:

  • out Vec2

    the receiving vector

  • a Vec2

    the vector to scale

  • b Number

    amount to scale the vector by

Returns:

out

scaleAndAdd

(
  • out
  • a
  • b
  • scale
)

Adds two vec2's after scaling the second operand by a scalar value

Parameters:

  • out Vec2

    the receiving vector

  • a Vec2

    the first operand

  • b Vec2

    the second operand

  • scale Number

    the amount to scale b by before adding

Returns:

out

set

(
  • out
  • x
  • y
)

Set the components of a vec2 to the given values

Parameters:

  • out Vec2

    the receiving vector

  • x Number

    X component

  • y Number

    Y component

Returns:

out

squaredDistance

(
  • a
  • b
)

Calculates the squared euclidian distance between two vec2's

Parameters:

  • a Vec2

    the first operand

  • b Vec2

    the second operand

Returns:

BinaryExpression

squaredLength

(
  • a
)

Calculates the squared length of a vec2

Parameters:

  • a Vec2

    vector to calculate squared length of

Returns:

BinaryExpression

str

(
  • a
)

Returns a string representation of a vector

Parameters:

Returns:

BinaryExpression

subtract

(
  • out
  • a
  • b
)

Subtracts vector b from vector a

Parameters:

  • out Vec2

    the receiving vector

  • a Vec2

    the first operand

  • b Vec2

    the second operand

Returns:

out

transformMat2

(
  • out
  • a
  • m
)

Transforms the vec2 with a mat2

Parameters:

  • out Vec2

    the receiving vector

  • a Vec2

    the vector to transform

  • m Mat2

    matrix to transform with

Returns:

out

transformMat2d

(
  • out
  • a
  • m
)

Transforms the vec2 with a mat2d

Parameters:

  • out Vec2

    the receiving vector

  • a Vec2

    the vector to transform

  • m Mat2d

    matrix to transform with

Returns:

out

transformMat3

(
  • out
  • a
  • m
)

Transforms the vec2 with a mat3 3rd vector component is implicitly '1'

Parameters:

  • out Vec2

    the receiving vector

  • a Vec2

    the vector to transform

  • m Mat3

    matrix to transform with

Returns:

out

transformMat4

(
  • out
  • a
  • m
)

Transforms the vec2 with a mat4 3rd vector component is implicitly '0' 4th vector component is implicitly '1'

Parameters:

  • out Vec2

    the receiving vector

  • a Vec2

    the vector to transform

  • m Mat4

    matrix to transform with

Returns:

out