Facebook Twitter YouTube

class Vector4D

Defined in:  TSVector4D.h
The Vector4D class encapsulates a 4D vector.
Definition

class Vector4D : public Vec4D<float>

Member Functions
Vector4D::Set Sets all four components of a vector.
Vector4D::Normalize Normalizes a 4D vector.
Vector4D::Standardize Standardizes a 4D vector.
Vector4D::GetVector3D Returns a reference to a Vector3D object.
Vector4D::GetPoint3D Returns a reference to a Point3D object.
Vector4D::GetVector2D Returns a reference to a Vector2D object.
Vector4D::RotateAboutX Rotates a vector about the x axis.
Vector4D::RotateAboutY Rotates a vector about the y axis.
Vector4D::RotateAboutZ Rotates a vector about the z axis.
Vector4D::RotateAboutAxis Rotates a vector about a given axis.
Constructor

Vector4D();

Vector4D(float a, float b, float c, float d);

template <typename type> explicit Vector4D(const Vec4D<type>& v);

Vector4D(const Vector3D& v, float d);

Vector4D(const Vector3D& v);

Vector4D(const Point3D& p);

Vector4D(const Vector2D& v);

Vector4D(const Point2D& p);

Parameters
a The value of the x coordinate.
b The value of the y coordinate.
c The value of the z coordinate.
d The value of the w coordinate.
v (Template constructor) Another 4D vector, possibly with a different component type, that is converted to a Vector4D.
v A 3D vector whose entries are copied to the x, y, and z coordinates.
p A 3D point whose entries are copied to the x, y, and z coordinates.
Description
The Vector4D class is used to store a four-dimensional vector having floating-point components x, y, z, and w.

The default constructor leaves the components of the vector undefined. If the values a, b, c, and d are supplied, then they are assigned to the x, y, z, and w coordinates of the vector, respectively. If the Vector4D object is constructed using a Vector3D or Vector2D object, then the w coordinate is set to 0. If the Vector4D object is constructed using a Point3D or Point2D object, then the w coordinate is set to 1. The z coordinate of a 2D vector or point is assumed to be 0.
Overloaded Operators
Vector4D& operator =(const Vector3D& v); Copies the x, y, and z coordinates of v, and assigns a value of 0 to the w coordinate.
Vector4D& operator =(const Point3D& p); Copies the x, y, and z coordinates of p, and assigns a value of 1 to the w coordinate.
Vector4D& operator =(const Vector2D& v); Copies the x and y coordinates of v, assigns a value of 0 to the z coordinate, and assigns a value of 0 to the w coordinate.
Vector4D& operator =(const Point2D& p); Copies the x and y coordinates of p, assigns a value of 0 to the z coordinate, and assigns a value of 1 to the w coordinate.
Vector4D& operator +=(const Vector4D& v); Adds the vector v.
Vector4D& operator +=(const Vector3D& v); Adds the vector v. The w coordinate is not modified.
Vector4D& operator +=(const Vector2D& v); Adds the vector v. The z and w coordinates are not modified.
Vector4D& operator -=(const Vector4D& v); Subtracts the vector v.
Vector4D& operator -=(const Vector3D& v); Subtracts the vector v. The w coordinate is not modified.
Vector4D& operator -=(const Vector2D& v); Subtracts the vector v. The z and w coordinates are not modified.
Vector4D& operator *=(float s); Multiplies by the scalar s.
Vector4D& operator /=(float s); Multiplies by the inverse of the scalar s.
Vector4D& operator *=(const Vector4D& v); Calculates the componentwise product with the vector v.
Nonmember Operations
Vector4D operator -(const Vector4D& v); Returns the negation of the vector v.
Vector4D operator +(const Vector4D& a, const Vector4D& b); Returns the sum of the vectors a and b.
Vector4D operator +(const Vector4D& a, const Vector3D& b); Returns the sum of the vectors a and b. The w coordinate of b is assumed to be 0.
Vector4D operator +(const Vector3D& a, const Vector4D& b); Returns the sum of the vectors a and b. The w coordinate of a is assumed to be 0.
Vector4D operator +(const Vector4D& a, const Vector2D& b); Returns the sum of the vectors a and b. The z and w coordinates of b are assumed to be 0.
Vector4D operator +(const Vector2D& a, const Vector4D& b); Returns the sum of the vectors a and b. The z and w coordinates of a are assumed to be 0.
Vector4D operator -(const Vector4D& a, const Vector4D& b); Returns the difference of the vectors a and b.
Vector4D operator -(const Vector4D& a, const Vector3D& b); Returns the difference of the vectors a and b. The w coordinate of b is assumed to be 0.
Vector4D operator -(const Vector3D& a, const Vector4D& b); Returns the difference of the vectors a and b. The w coordinate of a is assumed to be 0.
Vector4D operator -(const Vector4D& a, const Vector2D& b); Returns the difference of the vectors a and b. The z and w coordinates of b are assumed to be 0.
Vector4D operator -(const Vector2D& a, const Vector4D& b); Returns the difference of the vectors a and b. The z and w coordinates of a are assumed to be 0.
Vector4D operator *(const Vector4D& v, float f); Returns the product of the vector v and the scalar f.
Vector4D operator *(float f, const Vector4D& v); Returns the product of the vector v and the scalar f.
Vector4D operator /(const Vector4D& v, float f); Returns the product of the vector v and the inverse of the scalar f.
Vector4D operator *(const Vector4D& a, const Vector4D& b); Returns the componentwise product of the vectors a and b.
float Dot(const Vector4D& a, const Vector4D& b); Returns the four-dimensional dot product between a and b.
float Dot(const Vector4D& a, const Vector3D& b); Returns the dot product of the vectors a and b. The w coordinate of b is assumed to be 0.
float Dot(const Vector3D& a, const Vector4D& b); Returns the dot product of the vectors a and b. The w coordinate of a is assumed to be 0.
float Dot(const Vector4D& v, const Point3D& p); Returns the dot product of the vector v and the point p. The w coordinate of p is assumed to be 1.
float Dot(const Point3D& p, const Vector4D& v); Returns the dot product of the point p and the vector v. The w coordinate of p is assumed to be 1.
float Dot(const Vector4D& a, const Vector2D& b); Returns the dot product with the vector v. The z and w coordinates of b are assumed to be 0.
float Dot(const Vector2D& a, const Vector4D& b); Returns the dot product of the vectors a and b. The z and w coordinates of a is assumed to be 0.
float Dot(const Vector4D& v, const Point2D& p); Returns the dot product of the vector v and the point p. The z coordinate of p is assumed to be 0, and the w coordinate of p is assumed to be 1.
float Dot(const Point2D& p, const Vector4D& v); Returns the dot product of the point p and the vector v. The z coordinate of p is assumed to be 0, and the w coordinate of p is assumed to be 1.
Vector4D Project(const Vector4D& a, const Vector4D& b); Returns (a ⋅ b)b, which is the projection of a onto b under the assumption that the magnitude of b is one.
Vector3D Reject(const Vector3D& a, const Vector3D& 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 Vector4D& v); Returns the magnitude of the vector v.
float InverseMag(const Vector4D& v); Returns the inverse magnitude of the vector v.
float SquaredMag(const Vector4D& v); Returns the squared magnitude of the vector v.
Base Classes
Vec4D Vectors use a generic base class to store their components.
See Also

Trivector4D

Vector3D

Point3D

Vector2D

Point2D