30 lines
632 B
C++
30 lines
632 B
C++
|
|
#include <stdlib.h> /* rand() */
|
|
#include <math.h>
|
|
|
|
#include <iostream>
|
|
|
|
#include "Vector.h"
|
|
|
|
const Vector Vector::X(1, 0, 0);
|
|
const Vector Vector::Y(0, 1, 0);
|
|
const Vector Vector::Z(0, 0, 1);
|
|
|
|
Vector Vector::randomVector()
|
|
{
|
|
double x, y, z;
|
|
do
|
|
{
|
|
x = 2.0 * rand() / RAND_MAX - 1.0;
|
|
y = 2.0 * rand() / RAND_MAX - 1.0;
|
|
z = 2.0 * rand() / RAND_MAX - 1.0;
|
|
} while (x*x + y*y + z*z > 1.0);
|
|
return Vector(x, y, z).normalize();
|
|
}
|
|
|
|
std::ostream & operator<<(std::ostream & out, const Vector & v)
|
|
{
|
|
out << "[" << v[0] << ", " << v[1] << ", " << v[2] << "]";
|
|
return out;
|
|
}
|