Currently incomplete!

Vector2
Vector2.createPolar
Vector2.ZERO
Vector2.X_UNIT
Vector2.Y_UNIT
magnitude
magnitudeSquared
distance
distanceSquared
dot
crossScalar
equals
equalsEpsilon
isFinite
copy
normalized
componentTimes
times
timesScalar
plus
plusScalar
minus
minusScalar
dividedScalar
negated
angle
angleBetween
rotated
perpendicular
blend
toVector3
set
setX
setY
add
addScalar
subtract
subtractScalar
componentMultiply
divideScalar
negate
Bounds2
Matrix3
Transform3
Ray2
Util

Tutorials

Add one!

Get the code

Dot depends on a few other libraries, and needs to have them checked out as siblings. It is recommended to place all of these inside a containing directory. Make sure you have git installed, then run:

git clone https://github.com/phetsims/sherpa.git
git clone https://github.com/phetsims/chipper.git
git clone https://github.com/phetsims/assert.git
git clone https://github.com/phetsims/phet-core.git
git clone https://github.com/phetsims/dot.git

For some examples and tests, and to build a custom version, you'll need to install node.js, and grunt-cli. Then,

cd dot
npm install
grunt

You will now have the built files under build/

Dependencies

External dependencies (please provide these in your page before loading Dot): Internal dependencies:

Dot API

Vector2

A 2-dimensional vector that is also used to represent points (as a vector from the origin). new dot.Vector2( x, y ) will create a vector, and new dot.Vector2() will create a new Vector2 with x=0 and y=0. For immutable use, it is recommended to use a reference to dot.Vector2.ZERO instead.

Below, $ u $ will be used to denote the this vector reference, and $ v $ will denote the vector parameter reference.

Vector2.createPolar( magnitude, angle )

Returns a Vector2 with the specified magnitude $r$ and angle $\theta$ (in radians), with the formula: $$ \left[ \begin{array}{ccc} r\cos\theta \\ r\sin\theta \end{array} \right] $$

Vector2.ZERO

Immutable instance of $ \left[ \begin{array}{ccc} 0 \\ 0 \end{array} \right] $

Vector2.X_UNIT

Immutable instance of $ \left[ \begin{array}{ccc} 1 \\ 0 \end{array} \right] $

Vector2.Y_UNIT

Immutable instance of $ \left[ \begin{array}{ccc} 0 \\ 1 \end{array} \right] $

magnitude()

Returns the magnitude (Euclidian 2-norm) of the vector: $ \lvert u \rvert = \sqrt{x^2 + y^2} $

magnitudeSquared()

Returns the squared magnitude of the vector: $ \lvert u \rvert^2 = x^2 + y^2 $

distance( vector )

Returns the distance $ \lvert u-v \rvert $ between this vector and the specified vector (both treated as points).

distanceSquared( vector )

Returns the squared distance $ \lvert u-v \rvert^2 $ between this vector and the specified vector (both treated as points).

dot( vector )

Returns the scalar dot product $ u_x v_y + u_y v_x $ between this vector and the specified vector.

crossScalar( vector )

Returns the scalar value of the z-component of the equivalent 3-dimensional cross product $$ \left( \left[ \begin{array}{ccc} u_x \\ u_y \\ 0 \end{array} \right] \times \left[ \begin{array}{ccc} v_x \\ v_y \\ 0 \end{array} \right] \right)_z = u_x v_y - u_y v_x $$

equals( vector )

Returns true iff the vectors are component-wise identical.

equalsEpsilon( vector, ε )

Returns true iff the $\infty$-norm of the difference $ \lvert\lvert u-v \rvert\rvert_\infty < ε $. The $\infty$-norm was chosen to best represent floating point error handling in each dimension.

isFinite()

Returns true iff both components $x$ and $y$ are finite (not NaN, $-\infty$ or $\infty$).

normalized()

Returns a normalized copy of this vector using the Euclidean norm. This is equivalent to dividing the vector by the magnitude, and will throw an error if the division is by zero.

componentTimes( v )

Returns a copy of this vector multiplied component-wise by the parameter vector $$ \left[ \begin{array}{ccc} u_x v_x \\ u_y v_y \end{array} \right] $$

times( s )

Currently an alias for timesScalar. May also use componentTimes in the future if the argument is a Vector2.

timesScalar( s )

Returns a copy of the vector with each component multiplied times the scalar. $$ \left[ \begin{array}{ccc} s u_x \\ s u_y \end{array} \right] $$