Facebook Twitter YouTube

class Vector2D

Defined in:  TSVector2D.h
The Vector2D class encapsulates a 2D vector.

class Vector2D : public Vec2D<float>

Member Functions
Vector2D::Set Sets both components of a vector.
Vector2D::Normalize Normalizes a 2D vector.
Vector2D::Rotate Rotates a vector in the x-y plane.


Vector2D(float a, float b);

template <typename type> explicit Vector2D(const Vec2D<type>& v);

a The value of the x coordinate.
b The value of the y coordinate.
v Another 2D vector, possibly with a different component type, that is converted to a Vector2D.
The Vector2D class is used to store a two-dimensional direction vector having floating-point components x and y. A direction vector stored in this class is assumed to have a w coordinate of 0 whenever it needs to be converted to a four-dimensional representation. Two-dimensional points (for which the w coordinate is 1) should be stored using the Point2D class. The z coordinate of a 2D vector is always assumed to be 0.

The default constructor leaves the components of the vector undefined. If the values a and b are supplied, then they are assigned to the x and y coordinates of the vector, respectively.
Overloaded Operators
Vector2D& operator +=(const Vector2D& v); Adds the vector v.
Vector2D& operator -=(const Vector2D& v); Subtracts the vector v.
Vector2D& operator *=(float s); Multiplies by the scalar s.
Vector2D& operator /=(float s); Divides by the scalar s.
Vector2D& operator *=(const Vector2D& v); Calculates the componentwise product with the vector v.
Nonmember Operations
Vector2D operator -(const Vector2D& v) const; Returns the negation of the vector v.
Vector2D operator +(const Vector2D& a, const Vector2D& b) const; Returns the sum of the vectors a and b.
Vector2D operator -(const Vector2D& a, const Vector2D& b) const; Returns the difference of the vectors a and b.
Vector2D operator *(const Vector2D& v, float s) const; Returns the product of the vector v and the scalar s.
Vector2D operator *(float s, const Vector2D& v); Returns the product of the vector v and the scalar s.
Vector2D operator /(const Vector2D& v, float s) const; Returns the product of the vector v and the inverse of the scalar s.
Vector2D operator *(const Vector2D& a, const Vector2D& b) const; Returns the componentwise product of the vectors a and b.
float Dot(const Vector2D& a, const Vector2D& b); Returns the dot product between a and b.
Vector2D Project(const Vector2D& a, const Vector2D& b); Returns (a ⋅ b)b, which is the projection of a onto b under the assumption that the magnitude of b is one.
Vector2D Reject(const Vector2D& a, const Vector2D& b); Returns (a − a ⋅ b)b, which is the rejection of a from b under the assumption that the magnitude of b is one.
float Magnitude(const Vector2D& v); Returns the magnitude of the vector v.
float InverseMag(const Vector2D& v); Returns the inverse magnitude of the vector v.
float SquaredMag(const Vector2D& v); Returns the squared magnitude of the vector v.
Base Classes
Vec2D Vectors use a generic base class to store their components.
See Also