RayTracer 1.0
Ray tracing is a technique used to generate realistic digital images by simulating the inverse path of light. Our goal is to create a program able to generate an image from a file describing the scene.
 
Loading...
Searching...
No Matches
Math Namespace Reference

Classes

class  Point3D
 
class  Vector3D
 

Functions

Vector3D rotateVector (const Vector3D &v, const Vector3D &axis, double angleDegrees)
 

Function Documentation

◆ rotateVector()

Math::Vector3D Math::rotateVector ( const Vector3D & v,
const Vector3D & axis,
double angleDegrees )

Definition at line 90 of file Math3D.cpp.

91{
92 double rad = angleDegrees * M_PI / 180.0;
93 double cosA = std::cos(rad);
94 double sinA = std::sin(rad);
95
96 Math::Vector3D normalizedAxis = axis;
97 double len = normalizedAxis.length();
98 if (len != 0)
99 normalizedAxis = normalizedAxis / len;
100
101 double ux = normalizedAxis.x;
102 double uy = normalizedAxis.y;
103 double uz = normalizedAxis.z;
104
105 Math::Vector3D rotated;
106 rotated.x = (cosA + (1 - cosA) * ux * ux) * v.x
107 + ((1 - cosA) * ux * uy - sinA * uz) * v.y
108 + ((1 - cosA) * ux * uz + sinA * uy) * v.z;
109
110 rotated.y = ((1 - cosA) * uy * ux + sinA * uz) * v.x
111 + (cosA + (1 - cosA) * uy * uy) * v.y
112 + ((1 - cosA) * uy * uz - sinA * ux) * v.z;
113
114 rotated.z = ((1 - cosA) * uz * ux - sinA * uy) * v.x
115 + ((1 - cosA) * uz * uy + sinA * ux) * v.y
116 + (cosA + (1 - cosA) * uz * uz) * v.z;
117
118 return rotated;
119}
double length() const
Definition Math3D.cpp:15

References Math::Vector3D::length(), Math::Vector3D::x, Math::Vector3D::y, and Math::Vector3D::z.