1 #ifndef CMU462_VECTOR4D_H
2 #define CMU462_VECTOR4D_H
25 Vector4D() : x( 0.0 ), y( 0.0 ), z( 0.0 ), w( 0.0 ) { }
31 Vector4D(
double x,
double y,
double z,
double w) : x( x ), y( y ), z( z ), w( w ) { }
37 Vector4D(
double x,
double y,
double z) : x( x ), y( y ), z( z ), w( 0.0 ) { }
44 Vector4D(
double c ) : x( c ), y( c ), z( c ), w ( c ) { }
65 inline double& operator[] (
const int& index ) {
66 return ( &x )[ index ];
70 inline const double& operator[] (
const int& index )
const {
71 return ( &x )[ index ];
75 inline Vector4D operator-(
void )
const {
81 return Vector4D( x + v.x, y + v.y, z + v.z, w + v.w);
86 return Vector4D( x - v.x, y - v.y, z - v.z, w - v.w );
90 inline Vector4D operator*(
const double& c )
const {
91 return Vector4D( x * c, y * c, z * c, w * c );
95 inline Vector4D operator/(
const double& c )
const {
96 const double rc = 1.0/c;
97 return Vector4D( rc * x, rc * y, rc * z, rc * w );
101 inline void operator+=(
const Vector4D& v ) {
102 x += v.x; y += v.y; z += v.z; z += v.w;
106 inline void operator-=(
const Vector4D& v ) {
107 x -= v.x; y -= v.y; z -= v.z; w -= v.w;
111 inline void operator*=(
const double& c ) {
112 x *= c; y *= c; z *= c; w *= c;
116 inline void operator/=(
const double& c ) {
123 inline double norm(
void )
const {
124 return sqrt( x*x + y*y + z*z + w*w );
131 return x*x + y*y + z*z + w*w;
138 double rNorm = 1. / sqrt( x*x + y*y + z*z + w*w);
139 return Vector4D( rNorm*x, rNorm*y, rNorm*z );
163 inline Vector4D operator* (
const double& c,
const Vector4D& v ) {
164 return Vector4D( c * v.x, c * v.y, c * v.z, c*v.w );
168 inline double dot(
const Vector4D& u,
const Vector4D& v ) {
169 return u.x*v.x + u.y*v.y + u.z*v.z + u.w*v.w;;
173 std::ostream& operator<<( std::ostream& os,
const Vector4D& v );
177 #endif // CMU462_VECTOR3D_H
Vector4D(double x, double y, double z, double w)
Constructor.
Definition: vector4D.h:31
Vector3D to3D()
Converts this vector to a 3D vector ignoring the w component.
Definition: vector4D.cpp:10
Vector3D projectTo3D()
Converts this vector to a 3D vector by dividing x, y, and z by w.
Definition: vector4D.cpp:14
Vector4D unit(void) const
Returns unit vector.
Definition: vector4D.h:137
Defines 4D standard vectors.
Definition: vector4D.h:15
Defines 3D vectors.
Definition: vector3D.h:14
double norm(void) const
Returns Euclidean distance metric extended to 4 dimensions.
Definition: vector4D.h:123
Vector4D(const Vector4D &v)
Constructor.
Definition: vector4D.h:50
Vector4D(double x, double y, double z)
Constructor.
Definition: vector4D.h:37
double norm2(void) const
Returns Euclidean length squared.
Definition: vector4D.h:130
Vector4D(const Vector3D &v, double w)
Constructor.
Definition: vector4D.h:62
Vector4D(const Vector3D &v)
Constructor.
Definition: vector4D.h:56
Vector4D(double c)
Constructor.
Definition: vector4D.h:44
Vector4D()
Constructor.
Definition: vector4D.h:25
void normalize(void)
Divides by Euclidean length.
Definition: vector4D.h:146