EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Vector3D Class Reference

#include "Vector3D.h"

Public Member Functions

 Vector3D ()
 
 Vector3D (double nx, double ny, double nz)
 
 Vector3D (const Vector3D &v)
 
Vector3D copy () const
 
double magnitude () const
 
double length () const
 
double lengthSquared () const
 
void normalize ()
 
double dotProduct (const Vector3D &v) const
 
Vector3D crossProduct (const Vector3D &v) const
 
Vector3D reflection (Vector3D norm) const
 
Vector3D refraction (Vector3D norm, double fact) const
 
void set (double nx, double ny, double nz)
 
void set (const Vector3D &v)
 
bool operator== (const Vector3D &v)
 
bool operator!= (const Vector3D &v)
 
Vector3Doperator= (const Vector3D &v)
 
Vector3D operator+ (const Vector3D &v) const
 
Vector3Doperator+= (const Vector3D &v)
 
Vector3D operator- (const Vector3D &v) const
 
Vector3Doperator-= (const Vector3D &v)
 
Vector3D operator* (const Vector3D &v) const
 
Vector3Doperator*= (const Vector3D &v)
 
Vector3D operator/ (const Vector3D &v) const
 
Vector3Doperator/= (const Vector3D &v)
 
Vector3D operator* (const double &k) const
 
Vector3Doperator*= (const double &k)
 
Vector3D operator/ (const double &k) const
 
Vector3Doperator/= (const double &k)
 
bool isNotZero ()
 
void MakeRandomPointOnSphere (double radius)
 
void MakeRandomPointOnSphereLayer (double radiusInner, double radiusOuter)
 

Public Attributes

double x
 
double y
 
double z
 

Detailed Description

A 3 dimensional double vector.

Definition at line 37 of file Vector3D.h.

Constructor & Destructor Documentation

Vector3D::Vector3D ( )
inline

Definition at line 42 of file Vector3D.h.

Referenced by copy(), crossProduct(), operator*(), operator+(), operator-(), and operator/().

43  {
44  x = y = z = 0;
45  }
double z
Definition: Vector3D.h:40
double y
Definition: Vector3D.h:40
double x
Definition: Vector3D.h:40

Here is the caller graph for this function:

Vector3D::Vector3D ( double  nx,
double  ny,
double  nz 
)
inline

Definition at line 47 of file Vector3D.h.

48  {
49  x = nx;
50  y = ny;
51  z = nz;
52  }
double z
Definition: Vector3D.h:40
double y
Definition: Vector3D.h:40
double x
Definition: Vector3D.h:40
Vector3D::Vector3D ( const Vector3D v)
inline

Definition at line 54 of file Vector3D.h.

References x, y, and z.

55  {
56  x = v.x;
57  y = v.y;
58  z = v.z;
59  }
double z
Definition: Vector3D.h:40
double y
Definition: Vector3D.h:40
double x
Definition: Vector3D.h:40

Member Function Documentation

Vector3D Vector3D::copy ( ) const
inline

Return a copy of the vector.

Returns
The copy of the vector.

Definition at line 65 of file Vector3D.h.

References Vector3D().

66  {
67  return Vector3D(*this);
68  }
Vector3D()
Definition: Vector3D.h:42

Here is the call graph for this function:

Vector3D Vector3D::crossProduct ( const Vector3D v) const

Calculate the cross product of this vector and the provided vector.

Parameters
vThe provided vector.
Returns
The cross product of the 2 vectors.
Note
The resultant vector is perpendicular to a plane formed by the two vectors.
The magnitude of the result is the area formed by the parallelogram of the two vectors.

Definition at line 64 of file Vector3D.cpp.

References Vector3D(), x, y, and z.

65 {
66  double nx = y * v.z - z * v.y;
67  double ny = z * v.x - x * v.z;
68  double nz = x * v.y - y * v.x;
69  return Vector3D(nx, ny, nz);
70 }
double z
Definition: Vector3D.h:40
double y
Definition: Vector3D.h:40
Vector3D()
Definition: Vector3D.h:42
double x
Definition: Vector3D.h:40

Here is the call graph for this function:

double Vector3D::dotProduct ( const Vector3D v) const

Calculate the dot product of this vector and the provided vector.

Parameters
vThe provided vector.
Returns
The dot product.
Note
If both Vectors are unit Vectors then the result is the cosine of the angle between them. otherwise it's scaled by the product of there lengths.

Definition at line 59 of file Vector3D.cpp.

References x, y, and z.

Referenced by reflection(), and refraction().

60 {
61  return ((x * v.x) + (y * v.y) + (z * v.z));
62 }
double z
Definition: Vector3D.h:40
double y
Definition: Vector3D.h:40
double x
Definition: Vector3D.h:40

Here is the caller graph for this function:

bool Vector3D::isNotZero ( )
inline

Definition at line 163 of file Vector3D.h.

164  {
165  return x != 0 || y != 0 || z != 0;
166  }
double z
Definition: Vector3D.h:40
double y
Definition: Vector3D.h:40
double x
Definition: Vector3D.h:40
double Vector3D::length ( ) const
inline

Definition at line 76 of file Vector3D.h.

References magnitude().

77  {
78  return magnitude();
79  }
double magnitude() const
Definition: Vector3D.cpp:28

Here is the call graph for this function:

double Vector3D::lengthSquared ( ) const
inline

Definition at line 81 of file Vector3D.h.

References y.

82  {
83  return (x * x) + (y * y) + (z * z);
84  }
double z
Definition: Vector3D.h:40
double y
Definition: Vector3D.h:40
double x
Definition: Vector3D.h:40
double Vector3D::magnitude ( ) const

Retrieves the length of the Vector.

Returns
The length of the vector.

Definition at line 28 of file Vector3D.cpp.

References x, y, and z.

Referenced by length().

29 {
30  double m;
31 
32  //calculate the length of the Vector3D
33  m = (x * x) + (y * y) + (z * z);
34  m = sqrt(m);
35 
36  return m;
37 }
double z
Definition: Vector3D.h:40
double y
Definition: Vector3D.h:40
double x
Definition: Vector3D.h:40

Here is the caller graph for this function:

void Vector3D::MakeRandomPointOnSphere ( double  radius)
inline

Definition at line 173 of file Vector3D.h.

References MakeRandomFloat().

174  {
175  double theta = MakeRandomFloat(0.0, (2 * M_PI));
176  double phi = MakeRandomFloat(0.0, (2 * M_PI));
177  x += radius * sin(theta) * cos(phi);
178  y += radius * sin(theta) * sin(phi);
179  z += radius * cos(theta);
180  }
double z
Definition: Vector3D.h:40
double MakeRandomFloat(double low, double high)
Generates random real from interval [low; high].
Definition: misc.cpp:114
double y
Definition: Vector3D.h:40
double x
Definition: Vector3D.h:40

Here is the call graph for this function:

void Vector3D::MakeRandomPointOnSphereLayer ( double  radiusInner,
double  radiusOuter 
)
inline

Definition at line 187 of file Vector3D.h.

References MakeRandomFloat().

188  {
189  double theta = MakeRandomFloat(0.0, (2 * M_PI));
190  double phi = MakeRandomFloat(0.0, (2 * M_PI));
191  double intermediateRadius = MakeRandomFloat(radiusInner, radiusOuter);
192  x += intermediateRadius * sin(theta) * cos(phi);
193  y += intermediateRadius * sin(theta) * sin(phi);
194  z += intermediateRadius * cos(theta);
195  }
double z
Definition: Vector3D.h:40
double MakeRandomFloat(double low, double high)
Generates random real from interval [low; high].
Definition: misc.cpp:114
double y
Definition: Vector3D.h:40
double x
Definition: Vector3D.h:40

Here is the call graph for this function:

void Vector3D::normalize ( )

Scale the Vector so it has a length of 1.

Definition at line 39 of file Vector3D.cpp.

References x, y, and z.

40 {
41  double m;
42 
43  //calculate the length of the Vector3D
44  m = (x * x) + (y * y) + (z * z);
45  m = sqrt(m);
46 
47  // if the length is zero then the Vector3D is zero so return
48  if (m == 0)
49  {
50  return;
51  }
52 
53  //Scale the Vector3D to a unit length
54  x /= m;
55  y /= m;
56  z /= m;
57 }
double z
Definition: Vector3D.h:40
double y
Definition: Vector3D.h:40
double x
Definition: Vector3D.h:40
bool Vector3D::operator!= ( const Vector3D v)
inline

Definition at line 141 of file Vector3D.h.

References x, y, and z.

142  {
143  return v.x != x || v.y != y || v.z != z;
144  }
double z
Definition: Vector3D.h:40
double y
Definition: Vector3D.h:40
double x
Definition: Vector3D.h:40
Vector3D Vector3D::operator* ( const Vector3D v) const

Definition at line 143 of file Vector3D.cpp.

References Vector3D().

144 {
145  return Vector3D(*this) *= v;
146 }
Vector3D()
Definition: Vector3D.h:42

Here is the call graph for this function:

Vector3D Vector3D::operator* ( const double &  k) const

Definition at line 169 of file Vector3D.cpp.

References Vector3D().

170 {
171  return Vector3D(*this) *= k;
172 }
Vector3D()
Definition: Vector3D.h:42

Here is the call graph for this function:

Vector3D & Vector3D::operator*= ( const Vector3D v)

Definition at line 148 of file Vector3D.cpp.

References x, y, and z.

149 {
150  x *= v.x;
151  y *= v.y;
152  z *= v.z;
153  return *this;
154 }
double z
Definition: Vector3D.h:40
double y
Definition: Vector3D.h:40
double x
Definition: Vector3D.h:40
Vector3D & Vector3D::operator*= ( const double &  k)

Definition at line 174 of file Vector3D.cpp.

References x, y, and z.

175 {
176  x *= k;
177  y *= k;
178  z *= k;
179  return *this;
180 }
double z
Definition: Vector3D.h:40
double y
Definition: Vector3D.h:40
double x
Definition: Vector3D.h:40
Vector3D Vector3D::operator+ ( const Vector3D v) const

Definition at line 117 of file Vector3D.cpp.

References Vector3D().

118 {
119  return Vector3D(*this) += v;
120 }
Vector3D()
Definition: Vector3D.h:42

Here is the call graph for this function:

Vector3D & Vector3D::operator+= ( const Vector3D v)

Definition at line 122 of file Vector3D.cpp.

References x, y, and z.

123 {
124  x += v.x;
125  y += v.y;
126  z += v.z;
127  return *this;
128 }
double z
Definition: Vector3D.h:40
double y
Definition: Vector3D.h:40
double x
Definition: Vector3D.h:40
Vector3D Vector3D::operator- ( const Vector3D v) const

Definition at line 130 of file Vector3D.cpp.

References Vector3D().

131 {
132  return Vector3D(*this) -= v;
133 }
Vector3D()
Definition: Vector3D.h:42

Here is the call graph for this function:

Vector3D & Vector3D::operator-= ( const Vector3D v)

Definition at line 135 of file Vector3D.cpp.

References x, y, and z.

136 {
137  x -= v.x;
138  y -= v.y;
139  z -= v.z;
140  return *this;
141 }
double z
Definition: Vector3D.h:40
double y
Definition: Vector3D.h:40
double x
Definition: Vector3D.h:40
Vector3D Vector3D::operator/ ( const Vector3D v) const

Definition at line 156 of file Vector3D.cpp.

References Vector3D().

157 {
158  return Vector3D(*this) /= v;
159 }
Vector3D()
Definition: Vector3D.h:42

Here is the call graph for this function:

Vector3D Vector3D::operator/ ( const double &  k) const

Definition at line 182 of file Vector3D.cpp.

References Vector3D().

183 {
184  return Vector3D(*this) /= k;
185 }
Vector3D()
Definition: Vector3D.h:42

Here is the call graph for this function:

Vector3D & Vector3D::operator/= ( const Vector3D v)

Definition at line 161 of file Vector3D.cpp.

References x, y, and z.

162 {
163  x /= v.x;
164  y /= v.y;
165  z /= v.z;
166  return *this;
167 }
double z
Definition: Vector3D.h:40
double y
Definition: Vector3D.h:40
double x
Definition: Vector3D.h:40
Vector3D & Vector3D::operator/= ( const double &  k)

Definition at line 187 of file Vector3D.cpp.

References x, y, and z.

188 {
189  x /= k;
190  y /= k;
191  z /= k;
192  return *this;
193 }
double z
Definition: Vector3D.h:40
double y
Definition: Vector3D.h:40
double x
Definition: Vector3D.h:40
Vector3D & Vector3D::operator= ( const Vector3D v)

Definition at line 109 of file Vector3D.cpp.

References x, y, and z.

110 {
111  x = v.x;
112  y = v.y;
113  z = v.z;
114  return *this;
115 }
double z
Definition: Vector3D.h:40
double y
Definition: Vector3D.h:40
double x
Definition: Vector3D.h:40
bool Vector3D::operator== ( const Vector3D v)
inline

Definition at line 137 of file Vector3D.h.

References x, y, and z.

138  {
139  return v.x == x && v.y == y && v.z == z;
140  }
double z
Definition: Vector3D.h:40
double y
Definition: Vector3D.h:40
double x
Definition: Vector3D.h:40
Vector3D Vector3D::reflection ( Vector3D  norm) const

Calculate the reflection vector for a surface with the specified normal.

Parameters
normThe surface normal of the surface to reflect from.
Returns
The reflection vector.

Definition at line 72 of file Vector3D.cpp.

References dotProduct().

73 {
74  Vector3D refl;
75  refl = norm * (-2 * dotProduct(norm));
76  refl = (*this) - refl;
77  return refl;
78 }
double dotProduct(const Vector3D &v) const
Definition: Vector3D.cpp:59

Here is the call graph for this function:

Vector3D Vector3D::refraction ( Vector3D  norm,
double  fact 
) const

Calculate the refraction vector for a surface with the specified normal.

Parameters
normThe surface normal of the surface to refract through.
factThe refraction factor.
Returns
The refraction vector.

Definition at line 80 of file Vector3D.cpp.

References dotProduct().

81 {
82  Vector3D refr;
83  double n_r = this->dotProduct(norm);
84  double k = 1 - (n_r * n_r);
85  k = 1 - (fact * fact) * k;
86  if (k < 0)
87  {
88  return refr;
89  }
90  refr = (*this) * fact;
91  refr -= norm * (fact * n_r + sqrt(k));
92  return refr;
93 }
double dotProduct(const Vector3D &v) const
Definition: Vector3D.cpp:59

Here is the call graph for this function:

void Vector3D::set ( double  nx,
double  ny,
double  nz 
)

Set the values of the vector.

Parameters
nxThe new value for X.
nyThe new value for Y.
nzThe new value for Z.

Definition at line 95 of file Vector3D.cpp.

References x, y, and z.

96 {
97  x = nx;
98  y = ny;
99  z = nz;
100 }
double z
Definition: Vector3D.h:40
double y
Definition: Vector3D.h:40
double x
Definition: Vector3D.h:40
void Vector3D::set ( const Vector3D v)

Set the values of the vector.

Parameters
vThe new value for the vector.

Definition at line 102 of file Vector3D.cpp.

References x, y, and z.

103 {
104  x = v.x;
105  y = v.y;
106  z = v.z;
107 }
double z
Definition: Vector3D.h:40
double y
Definition: Vector3D.h:40
double x
Definition: Vector3D.h:40

Member Data Documentation


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