Vector2

Represents a two-dimensional vector.  A quantity specified by a magnitude and a direction.  Vector is oriented in classical 2D graphics format with origin at top corner of screen.

Operators

  • Vector2 == Vector2
  • Vector2 != Vector2
  • Vector2 + Vector2
  • Vector2 - Vector2
  • Vector2 * scalar or scalar * Vector2
  • Vector2 / scalar
  • Vector2 += Vector2
  • Vector2 -= Vector2
  • Vector2 *= scalar
  • Vector2 /= scalar
  • ostream& << Vector2
Summary
Represents a two-dimensional vector.
x component of vector
y component of vector
Initializes zero length vector.
Initialize vector given an x and y component.
Initialize vector given an x and y component.
resolve vector, given a magnitude & angle in degrees.
resolve vector, given a magnitude & angle in radians.
Normalizes the vector.
Calculates dot product of two vectors.
Get length of vector.
Angle of vector in degrees, angle is calculated with respect to positive X axis.
Angle of vector in radians, angle is calculated with respect to positive X axis.
Calculate the normal vector.
Calculates angle between two vectors.
Calculates angle between two vectors.
Find length of a vector.
Determine distance between two points.
Alias for Vector2 type.

Data Members

x

scalar x

x component of vector

y

scalar y

y component of vector

(Con/ De)structors

Vector2

Vector2()

Initializes zero length vector.

Vector2

Vector2(scalar nx,
scalar ny)

Initialize vector given an x and y component.

Parameters

nxX component of vector.
nyY component of vector.

See Also

set

General

set

void set(scalar nx,
scalar ny)

Initialize vector given an x and y component.

Parameters

nxX component of vector.
nyY component of vector.

See Also

set

resolveDeg

void resolveDeg(scalar magnitude,
scalar angle)

resolve vector, given a magnitude & angle in degrees.

Parameters

magnitudeMagnitude of new vector.
angleAngle of new vector, in degrees.

See Also

resolveRad

resolveRad

void resolveRad(scalar magnitude,
scalar angle)

resolve vector, given a magnitude & angle in radians.

Parameters

magnitudeMagnitude of new vector.
angleAngle of new vector, in radians.

See Also

resolveDeg

normalize

void normalize()

Normalizes the vector.  (makes it length of 1.0 but leaves ratio of components intact)

dot

scalar dot(const Vector2 &rhs) const

Calculates dot product of two vectors.

Parameters

rhsVector to calculate dot product with.

Returns

Dot product of two vectors.

Special Accessors

getMagnitude

scalar getMagnitude() const

Get length of vector.

Returns

Length of the vector.

getAngleDeg

scalar getAngleDeg() const

Angle of vector in degrees, angle is calculated with respect to positive X axis.

               |90�
|
|
180�-----------------------0� or 360�
|
|
|270�

Returns

Angle of vector (in degrees).

getAngleRad

scalar getAngleRad() const

Angle of vector in radians, angle is calculated with respect to positive X axis.

              | pi/2
|
|
pi-----------------------0 or 2pi
|
|
| 3pi/4

Returns

Angle of vector (in radians).

calcNormal

Vector2 calcNormal() const

Calculate the normal vector.

Returns

Normal vector (vector w/ magnitude of 1) but same angle.

calcInnerAngleRad

scalar calcInnerAngleRad(const Vector2 &vec) const

Calculates angle between two vectors.

Parameters

vecVector to calculate angle between.

Returns

Angle between the two vectors in radians.

calcInnerAngleDeg

scalar calcInnerAngleDeg(const Vector2 &vec) const

Calculates angle between two vectors.

Parameters

vecVector to calculate angle between.

Returns

Angle between the two vectors in degrees.

External Utilities

magnitude

scalar magnitude(const Vector2 &v)

Find length of a vector.  Same as a call to v.getMagnitude() but provided for convinience.

Parameters

vVector to calculate magnitude of

Returns

Length of the vector.

distance

scalar distance(const Vector2 &v1,
const Vector2 &v2)

Determine distance between two points.

Parameters

v1First point.
v2Second point.

Returns

Scalar distance between the two points.

Aliases

Point2

Alias for Vector2 type.

scalar x
x component of vector
scalar y
y component of vector
Vector2()
Initializes zero length vector.
void set(scalar nx,
scalar ny)
Initialize vector given an x and y component.
void resolveDeg(scalar magnitude,
scalar angle)
resolve vector, given a magnitude & angle in degrees.
void resolveRad(scalar magnitude,
scalar angle)
resolve vector, given a magnitude & angle in radians.
void normalize()
Normalizes the vector.
scalar dot(const Vector2 &rhs) const
Calculates dot product of two vectors.
scalar getMagnitude() const
Get length of vector.
scalar getAngleDeg() const
Angle of vector in degrees, angle is calculated with respect to positive X axis.
scalar getAngleRad() const
Angle of vector in radians, angle is calculated with respect to positive X axis.
Vector2 calcNormal() const
Calculate the normal vector.
scalar calcInnerAngleRad(const Vector2 &vec) const
Calculates angle between two vectors.
scalar calcInnerAngleDeg(const Vector2 &vec) const
Calculates angle between two vectors.
scalar magnitude(const Vector2 &v)
Find length of a vector.
scalar distance(const Vector2 &v1,
const Vector2 &v2)
Determine distance between two points.