Sprites for Processing  V2.1
 All Classes Functions Variables
sprites.maths.Vector2D Class Reference
Inheritance diagram for sprites.maths.Vector2D:

Public Member Functions

 Vector2D ()
 
 Vector2D (double x, double y)
 
 Vector2D (final Vector2D v)
 
void set (final Vector2D v)
 
void set (double x, double y)
 
double lengthSq ()
 
double length ()
 
double dot (final Vector2D v)
 
double dotNorm (final Vector2D v)
 
double angleBetween (final Vector2D v)
 
int sign (final Vector2D v)
 
Vector2D getPerp ()
 
double distanceSq (final Vector2D v)
 
double distance (final Vector2D v)
 
void normalize ()
 
void truncate (double max)
 
Vector2D getReverse ()
 
Vector2D getReflect (final Vector2D norm)
 
void add (final Vector2D v)
 
void add (double dx, double dy)
 
void sub (final Vector2D v)
 
void mult (double d)
 
void div (double d)
 
double[] toArray ()
 
String toString ()
 

Static Public Member Functions

static Vector2D add (final Vector2D v0, final Vector2D v1)
 
static Vector2D sub (final Vector2D v0, final Vector2D v1)
 
static Vector2D mult (final Vector2D v, double d)
 
static Vector2D div (final Vector2D v, double d)
 
static double distSq (final Vector2D v0, final Vector2D v1)
 
static double dist (final Vector2D v0, final Vector2D v1)
 
static double dot (final Vector2D v0, final Vector2D v1)
 
static Vector2D normalize (final Vector2D v)
 
static double angleBetween (Vector2D v0, Vector2D v1)
 
static boolean isSecondInFOVofFirst (final Vector2D posFirst, final Vector2D facingFirst, final Vector2D posSecond, double fov)
 

Public Attributes

double x
 
double y
 

Static Public Attributes

static final Vector2D ZERO = new Vector2D(0, 0)
 
static final Vector2D ONE = new Vector2D(1, 1)
 
static final Vector2D PLUS_I = new Vector2D(1, 0)
 
static final Vector2D MINUS_I = new Vector2D(-1, 0)
 
static final Vector2D PLUS_J = new Vector2D(0, 1)
 
static final Vector2D MINUS_J = new Vector2D(0, -1)
 
static final Vector2D NaN = new Vector2D(Double.NaN, Double.NaN)
 
static final Vector2D POSITIVE_INFINITY
 
static final Vector2D NEGATIVE_INFINITY
 
static final int CLOCKWISE = 1
 
static final int ANTI_CLOCKWISE = -1
 

Detailed Description

Author
Peter Lager

Constructor & Destructor Documentation

sprites.maths.Vector2D.Vector2D ( )

Default to the zero vector

sprites.maths.Vector2D.Vector2D ( double  x,
double  y 
)

Create a vector based on parameter values.

Parameters
x
y
sprites.maths.Vector2D.Vector2D ( final Vector2D  v)

Copy constructor

Parameters
vthe vector to copy

Member Function Documentation

void sprites.maths.Vector2D.add ( final Vector2D  v)

Add a vector to this one

Parameters
vthe vector to add
void sprites.maths.Vector2D.add ( double  dx,
double  dy 
)

Change the vector by the values specified

Parameters
dx
dy
static Vector2D sprites.maths.Vector2D.add ( final Vector2D  v0,
final Vector2D  v1 
)
static

Get a new vector that is the sum of 2 vectors.

Parameters
v0first vector
v1second vector
Returns
the sum of the 2 vectors
double sprites.maths.Vector2D.angleBetween ( final Vector2D  v)

Calculate the angle between this and another vector.

Parameters
vthe other vector
Returns
the angle betwwen in radians
static double sprites.maths.Vector2D.angleBetween ( Vector2D  v0,
Vector2D  v1 
)
static

Calculate the angle between two vectors.

Parameters
v0first vector
v1second vector
Returns
the angle between in radians
double sprites.maths.Vector2D.distance ( final Vector2D  v)

Get the distance between this and an other point.

Parameters
vthe other point
Returns
distance to other point
double sprites.maths.Vector2D.distanceSq ( final Vector2D  v)

Get the distance squared between this and an other point.

Parameters
vthe other point
Returns
distance to other point squared
void sprites.maths.Vector2D.div ( double  d)

Divide the vector by a scalar

Parameters
d
static Vector2D sprites.maths.Vector2D.div ( final Vector2D  v,
double  d 
)
static

Get a new vector that is a vector divided by a scalar

Parameters
vthe original vector
dthe divisor
Returns
the calculated vector
double sprites.maths.Vector2D.dot ( final Vector2D  v)

Calculate the dot product between two un-normalised vectors.

Parameters
vthe other vector
Returns
the dot product
double sprites.maths.Vector2D.dotNorm ( final Vector2D  v)

Calculate the dot product between two normalised vectors i.e. the cosine of the angle between them

Parameters
v
Returns
Vector2D sprites.maths.Vector2D.getPerp ( )

Get a vector perpendicular to this one.

Returns
a perpendicular vector
Vector2D sprites.maths.Vector2D.getReflect ( final Vector2D  norm)

Return the reflection vector about the norm

Parameters
norm
Returns
the reflected vector
Vector2D sprites.maths.Vector2D.getReverse ( )

Get a vector that is the reverse of this vector

Returns
the reverse vector
static boolean sprites.maths.Vector2D.isSecondInFOVofFirst ( final Vector2D  posFirst,
final Vector2D  facingFirst,
final Vector2D  posSecond,
double  fov 
)
static

Determines whether entity 2 is visible from entity 1.

Parameters
posFirstposition of first entity
facingFirstdirection first entity is facing
posSecondposition of second entity
fovfield of view (radians)
Returns
double sprites.maths.Vector2D.length ( )

Get the vector length

double sprites.maths.Vector2D.lengthSq ( )

Get the vector length squared

void sprites.maths.Vector2D.mult ( double  d)

Multiply the vector by a scalar

Parameters
d
static Vector2D sprites.maths.Vector2D.mult ( final Vector2D  v,
double  d 
)
static

Get a new vector that is the product of a vector and a scalar

Parameters
vthe original vector
dthe multiplier
Returns
the calculated vector
void sprites.maths.Vector2D.normalize ( )

Normalise this vector

static Vector2D sprites.maths.Vector2D.normalize ( final Vector2D  v)
static

Get a new vector that is the given vector normalised

Parameters
vthe original vector
Returns
the normalised vector
int sprites.maths.Vector2D.sign ( final Vector2D  v)

Determines whether vector v is clockwise of this vector.

Parameters
va vector
Returns
positive (+1) if clockwise else negative (-1)
static Vector2D sprites.maths.Vector2D.sub ( final Vector2D  v0,
final Vector2D  v1 
)
static

Get a new vector that is the difference between the 2 vectors.

Parameters
v0first vector
v1second vector
Returns
the difference between the 2 vectors
double [] sprites.maths.Vector2D.toArray ( )

Get the coordinates as an array.

Returns
void sprites.maths.Vector2D.truncate ( double  max)

Truncate this vector so its length is no greater than the value provided.

Parameters
maxmaximum size for this vector

Member Data Documentation

final Vector2D sprites.maths.Vector2D.MINUS_I = new Vector2D(-1, 0)
static

Opposite of the first canonical vector (coordinates: -1, 0).

final Vector2D sprites.maths.Vector2D.MINUS_J = new Vector2D(0, -1)
static

Opposite of the second canonical vector (coordinates: 0, -1).

final Vector2D sprites.maths.Vector2D.NaN = new Vector2D(Double.NaN, Double.NaN)
static

A vector with all coordinates set to NaN.

final Vector2D sprites.maths.Vector2D.NEGATIVE_INFINITY
static
Initial value:
=
new Vector2D(Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY)

A vector with all coordinates set to negative infinity.

final Vector2D sprites.maths.Vector2D.ONE = new Vector2D(1, 1)
static

Null vector (coordinates: 1, 1).

final Vector2D sprites.maths.Vector2D.PLUS_I = new Vector2D(1, 0)
static

First canonical vector (coordinates: 1, 0).

final Vector2D sprites.maths.Vector2D.PLUS_J = new Vector2D(0, 1)
static

Second canonical vector (coordinates: 0, 1).

final Vector2D sprites.maths.Vector2D.POSITIVE_INFINITY
static
Initial value:
=
new Vector2D(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY)

A vector with all coordinates set to positive infinity.

final Vector2D sprites.maths.Vector2D.ZERO = new Vector2D(0, 0)
static

Null vector (coordinates: 0, 0).


The documentation for this class was generated from the following file: