Currently incomplete!
Add one!
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/
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.
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] $$
Immutable instance of $ \left[ \begin{array}{ccc} 0 \\ 0 \end{array} \right] $
Immutable instance of $ \left[ \begin{array}{ccc} 1 \\ 0 \end{array} \right] $
Immutable instance of $ \left[ \begin{array}{ccc} 0 \\ 1 \end{array} \right] $
Returns the magnitude (Euclidian 2-norm) of the vector: $ \lvert u \rvert = \sqrt{x^2 + y^2} $
Returns the squared magnitude of the vector: $ \lvert u \rvert^2 = x^2 + y^2 $
Returns the distance $ \lvert u-v \rvert $ between this vector and the specified vector (both treated as points).
Returns the squared distance $ \lvert u-v \rvert^2 $ between this vector and the specified vector (both treated as points).
Returns the scalar dot product $ u_x v_y + u_y v_x $ between this vector and the specified 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 $$
Returns true iff the vectors are component-wise identical.
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.
Returns true iff both components $x$ and $y$ are finite (not NaN, $-\infty$ or $\infty$).
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.
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] $$
Currently an alias for timesScalar. May also use componentTimes in the future if the argument is a Vector2.
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] $$