AI for Games 1.1.1
Loading...
Searching...
No Matches
game2dai.maths.Vector2D Class Reference
Inheritance diagram for game2dai.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 get ()
 
Vector2D getPerp ()
 
double distanceSq (final Vector2D v)
 
double distance (final Vector2D v)
 
Vector2D normalize ()
 
Vector2D truncate (double max)
 
Vector2D getReverse ()
 
Vector2D getReflect (final Vector2D norm)
 
Vector2D add (final Vector2D v)
 
Vector2D add (double dx, double dy)
 
Vector2D sub (final Vector2D v)
 
Vector2D mult (double d)
 
Vector2D div (double d)
 
double[] toArray ()
 
String toShortString ()
 
String toString ()
 

Static Public Member Functions

static boolean areEqual (Vector2D v0, Vector2D v1)
 
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 Vector2D normalize (final Vector2D v)
 
static double angleBetween (Vector2D v0, Vector2D v1)
 
static boolean isSecondInFOVofFirstXXX (final Vector2D posFirst, final Vector2D facingFirst, final double fovFirst, final Vector2D posSecond)
 
static Vector2D random (Vector2D target)
 

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 double EPSILON = 1e-10
 
static final int CLOCKWISE = 1
 
static final int ANTI_CLOCKWISE = -1
 

Static Private Attributes

static final long serialVersionUID = -7691691832344874590L
 

Detailed Description

This 2D vector class uses the double data type throughout.

Constructor & Destructor Documentation

◆ Vector2D() [1/3]

game2dai.maths.Vector2D.Vector2D ( )

Default to the zero vector

◆ Vector2D() [2/3]

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

Create a vector based on parameter values.

Parameters
x
y

◆ Vector2D() [3/3]

game2dai.maths.Vector2D.Vector2D ( final Vector2D  v)

Copy constructor

Parameters
vthe vector to copy

Member Function Documentation

◆ add() [1/3]

Vector2D game2dai.maths.Vector2D.add ( double  dx,
double  dy 
)

Change the vector by the values specified

Parameters
dx
dy

◆ add() [2/3]

Vector2D game2dai.maths.Vector2D.add ( final Vector2D  v)

Add a vector to this one

Parameters
vthe vector to add

◆ add() [3/3]

static Vector2D game2dai.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

◆ angleBetween() [1/2]

double game2dai.maths.Vector2D.angleBetween ( final Vector2D  v)

Calculate the angle between this and another vector.

Parameters
vthe other vector
Returns
the angle between in radians

◆ angleBetween() [2/2]

static double game2dai.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

◆ dist()

static double game2dai.maths.Vector2D.dist ( final Vector2D  v0,
final Vector2D  v1 
)
static

The distance between two vectors

Parameters
v0the first vector
v1the second vector
Returns
the distance between them

◆ distance()

double game2dai.maths.Vector2D.distance ( final Vector2D  v)

Get the distance between this and an other point.

Parameters
vthe other point
Returns
distance to other point

◆ distanceSq()

double game2dai.maths.Vector2D.distanceSq ( final Vector2D  v)

Get the distance squared between this and another point.

Parameters
vthe other point
Returns
distance to other point squared

◆ distSq()

static double game2dai.maths.Vector2D.distSq ( final Vector2D  v0,
final Vector2D  v1 
)
static

The square of the distance between two vectors

Parameters
v0the first vector
v1the second vector
Returns
square of the distance between them

◆ div() [1/2]

Vector2D game2dai.maths.Vector2D.div ( double  d)

Divide the vector by a scalar

Parameters
d

◆ div() [2/2]

static Vector2D game2dai.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

◆ dot()

double game2dai.maths.Vector2D.dot ( final Vector2D  v)

Calculate the dot product between two un-normalised vectors.

Parameters
vthe other vector
Returns
the dot product

◆ dotNorm()

double game2dai.maths.Vector2D.dotNorm ( final Vector2D  v)

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

Parameters
vthe other vector
Returns
the cosine of angle between them

◆ get()

Vector2D game2dai.maths.Vector2D.get ( )

Get a copy (new object) of this vector.

Returns
a perpendicular vector

◆ getPerp()

Vector2D game2dai.maths.Vector2D.getPerp ( )

Get a vector perpendicular to this one.

Returns
a perpendicular vector

◆ getReflect()

Vector2D game2dai.maths.Vector2D.getReflect ( final Vector2D  norm)

Return the reflection vector about the norm

Parameters
norm
Returns
the reflected vector

◆ getReverse()

Vector2D game2dai.maths.Vector2D.getReverse ( )

Get a vector that is the reverse of this vector

Returns
the reverse vector

◆ isSecondInFOVofFirstXXX()

static boolean game2dai.maths.Vector2D.isSecondInFOVofFirstXXX ( final Vector2D  posFirst,
final Vector2D  facingFirst,
final double  fovFirst,
final Vector2D  posSecond 
)
static

Determines whether entity 2 is visible from entity 1.

Parameters
posFirstposition of first entity
facingFirstdirection first entity is facing
fovFirstfield of view (radians)
posSecondposition of second entity
Returns
true if second entity is inside 'visible' to the first entity

◆ length()

double game2dai.maths.Vector2D.length ( )

Get the vector length

◆ lengthSq()

double game2dai.maths.Vector2D.lengthSq ( )

Get the vector length squared

◆ mult() [1/2]

Vector2D game2dai.maths.Vector2D.mult ( double  d)

Multiply the vector by a scalar

Parameters
d

◆ mult() [2/2]

static Vector2D game2dai.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

◆ normalize() [1/2]

Vector2D game2dai.maths.Vector2D.normalize ( )

Normalise this vector

◆ normalize() [2/2]

static Vector2D game2dai.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

◆ random()

static Vector2D game2dai.maths.Vector2D.random ( Vector2D  target)
static

Create a random normalised vector.

Parameters
targetthe vector to randomise, create a vector if null
Returns
the randomised vector

◆ sign()

int game2dai.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)

◆ sub()

static Vector2D game2dai.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

◆ toArray()

double[] game2dai.maths.Vector2D.toArray ( )

Get the coordinates as an array.

◆ truncate()

Vector2D game2dai.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

◆ MINUS_I

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

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

◆ MINUS_J

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

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

◆ NaN

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

A vector with all coordinates set to NaN.

◆ NEGATIVE_INFINITY

final Vector2D game2dai.maths.Vector2D.NEGATIVE_INFINITY
static
Initial value:
=
new Vector2D(Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY)
Vector2D()
Definition Vector2D.java:82

A vector with all coordinates set to negative infinity.

◆ ONE

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

Null vector (coordinates: 1, 1).

◆ PLUS_I

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

First canonical vector (coordinates: 1, 0).

◆ PLUS_J

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

Second canonical vector (coordinates: 0, 1).

◆ POSITIVE_INFINITY

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

A vector with all coordinates set to positive infinity.

◆ ZERO

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

Null vector (coordinates: 0, 0).


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