point2line index
Name Vect2
Description Vect2 is a class for storing and manipulating vectors and positions in 2D.

WHY ANOTHER VECTOR CLASS?

There are a great number of open source vector classes available that does practically the same, so choosing a vector class for consistent use is mostly about taste. Processing already has the build-in PVector class by Daniel Shiffman. The main arguments for using Vect2 are:
  • Additional commonly used methods
  • Optimized convenience methods
  • Method chaining
Also, PVector is made for both 2D and 3D purposes which makes Vect2 slightly faster when working in 2D. I have chosen meaningful naming in favor of short keywords, making it more attractive for non-programmers.

ABOUT METHOD CHAINING

The methods that are named in past tense (eg. added(), flipped()) all return a copy of the vector, leaving the original untouched. These are all convenience methods that allow to make series of methods calls in one line. Example:
Vect2 force = pos1.subtracted(pos2).normalized.scaled(maxForce);

LICENCE

Vect2 is part of the point2line library. The library is free software; you can redistribute it and/or modify it for any desirable purpose. It is distributed in the hope that it will be useful, but without any warranty.

AUTHORS

Vect2 is maintained and updated by Carl Emil Carlsen in dialog with Daniel Hoeier Oehrgaard 2005+

Constructors
Vect2();
Vect2(x, y);
Vect2(vector);
Vect2(angle);
Parameters
x,y   components of new vector (float,float)
vector   to copy into new vector (Vect2)
angle   in radians to set the rotation of new unit vector (float)
Fields
x   The x component of the vector

y   The y component of the vector

Methods
add ( )   Adds an input vector to the vector and stores the result.

added ( )   Adds an input vector to the vector and returns the result.

angle ( )   Returns the angle of the vector.

angleBetween ( )   Returns the angle between two vectors (always positive).

angleBetweenUnits ( )   Returns the angle between two unit vectors (always positive).

angleFromTo ( )   Returns the angle between two unit vectors.

clip ( )   Clips the magnitude of the vector.

clipped ( )   Returns a copy of the vector that has been clipped.

clone ( )   Returns a clone of the vector.

copy ( )   Returns a copy of the vector (DEPRECIATED).

distance ( )   Returns the distance between to positions.

divide ( )   Divides the vector by a divider and stores the result.

divided ( )   Divides the vector by a divider and returns the result.

dot ( )   Returns the dot product of this vector and another.

equals ( )   Returns true if the vector is equals another vector

flip ( )   Flips the vector 180 degrees.

flipped ( )   Returns a copy that has been flipped.

isAlmostZero ( )   Returns true if the vector is almost zero.

isGreaterThan ( )   Returns true if the vector is longer than a specific magnitude.

isLessThan ( )   Returns true if the vector is shorter than a specific magnitude.

isZero ( )   Returns true if the vector is zero.

lerp ( )   Returns the linear interpolation between two vectors.

magnitude ( )   Returns the magnitude of the vector, also referred to as the length.

midpoint ( )   Returns the midpoint between two given vector points.

normalize ( )   Normalizes the vector.

normalized ( )   Returns a copy that has been normalized.

rotate ( )   Rotates the vector clockwise by a a delta angle.

rotateAround ( )   Rotates the position clockwise around another position by a a delta angle.

rotateLeft ( )   Rotates the vector 90 degrees left.

rotateRight ( )   Rotates the vector 90 degrees right.

rotated ( )   Returns copy that has been rotated clockwise by a delta angle.

rotatedAround ( )   Rotates the position clockwise around another position by a a delta angle.

rotatedLeft ( )   Returns a copy that has been rotated 90 degrees counter clockwise.

rotatedRight ( )   Returns a copy that has been rotated 90 degrees clockwise.

scale ( )   Multiplies the vector by an input value and stores the result.

scaled ( )   Multiplies the vector by an input value and returns the result.

set ( )   Sets the vector by copying.

setMagnitude ( )   Sets the magnitude (length) of the vector.

setRotation ( )   Sets the rotation of the vector.

setZero ( )   Sets the vector to zero (0,0).

squareMagnitude ( )   Returns the square magnitude of the vector.

subtract ( )   Subtracts an input from the vector and stores the result.

subtracted ( )   Subtracts and input vector from the vector and returns the result.

toString ( )   Returns a string containing the (x,y) components of this vector.

Usage Web & Application
Related
Examples
None available