64 Vec3D() { p[0] = 0.0; p[1] = 0.0; p[2] = 0.0; }
65 Vec3D(
double x ) { p[0] = x; p[1] = 0.0; p[2] = 0.0; }
66 Vec3D(
double x,
double y ) { p[0] = x; p[1] = y; p[2] = 0.0; }
67 Vec3D(
double x,
double y,
double z ) { p[0] = x; p[1] = y; p[2] = z; }
79 const double &
operator[](
int i )
const {
return( p[i] ); }
81 const double &
operator()(
int i )
const {
return( p[i] ); }
86 return(
Vec3D( p[0] + vec[0],
94 return(
Vec3D( p[0] - vec[0],
111 return( p[0] * vec[0] +
119 return(
Vec3D( x*p[0], x*p[1], x*p[2] ) );
125 return(
Vec3D( -p[0], -p[1], -p[2] ) );
165 bool approx(
const Vec3D &x,
double eps = 1.0e-6 )
const;
196 double inv_norm = 1.0/sqrt( p[0]*p[0] + p[1]*p[1] + p[2]*p[2] );
207 return( sqrt( p[0]*p[0] + p[1]*p[1] + p[2]*p[2] ) );
215 return( p[0]*p[0] + p[1]*p[1] + p[2]*p[2] );
228 void save( std::ostream &os )
const {
261 return( vec.
norm2() );
266 return(
Vec3D( vec1[1] * vec2[2] - vec1[2] * vec2[1],
267 vec1[2] * vec2[0] - vec1[0] * vec2[2],
268 vec1[0] * vec2[1] - vec1[1] * vec2[0] ) );
274 return(
Vec3D( x*vec.p[0], x*vec.p[1], x*vec.p[2] ) );
280 os << std::setw(12) <<
to_string(vec[0]).substr(0,12) <<
" ";
281 os << std::setw(12) <<
to_string(vec[1]).substr(0,12) <<
" ";
282 os << std::setw(12) <<
to_string(vec[2]).substr(0,12);
294 Int3D() { l[0] = 0; l[1] = 0; l[2] = 0; }
295 Int3D( int32_t i ) { l[0] = i; l[1] = 0; l[2] = 0; }
296 Int3D( int32_t i, int32_t j ) { l[0] = i; l[1] = j; l[2] = 0; }
297 Int3D( int32_t i, int32_t j, int32_t k ) { l[0] = i; l[1] = j; l[2] = k; }
311 return(
Int3D( l[0] - i[0],
317 return(
Vec3D( x*l[0], x*l[1], x*l[2] ) );
323 if( l[0] != i.l[0] || l[1] != i.l[1] || l[2] != i.l[2] )
331 if( l[0] == i.l[0] && l[1] == i.l[1] && l[2] == i.l[2] )
336 void save( std::ostream &s )
const {
359 os << std::setw(12) <<
to_string(vec[0]).substr(0,12) <<
" ";
360 os << std::setw(12) <<
to_string(vec[1]).substr(0,12) <<
" ";
361 os << std::setw(12) <<
to_string(vec[2]).substr(0,12);
static Vec3D standard_basis(int i)
Returns standard basis vector i.
bool operator!=(const Vec3D &x) const
Inequality test.
Vec3D operator*(double x)
Definition: vec3d.hpp:316
Vec3D(double x, double y)
Definition: vec3d.hpp:66
Vec3D cross(const Vec3D &vec1, const Vec3D &vec2)
Definition: vec3d.hpp:265
Vec3D operator+(const Vec3D &vec) const
Vector addition
Definition: vec3d.hpp:85
int min_element(void) const
Returns the index of element with minimum magnitude (abs).
void write_int32(std::ostream &os, int32_t value)
Write int32_t value into stream os.
double & operator()(int i)
Definition: vec3d.hpp:80
std::ostream & operator<<(std::ostream &os, const Vec3D &vec)
Definition: vec3d.hpp:278
Vec3D & operator=(const Vec3D &x)
Assignment.
Definition: vec3d.hpp:169
const int32_t & operator[](int i) const
Definition: vec3d.hpp:306
Vec3D()
Definition: vec3d.hpp:64
Int3D(std::istream &s)
Definition: vec3d.hpp:298
double norm2(const Vec3D &vec)
Definition: vec3d.hpp:260
Vec3D arb_perpendicular(void) const
Returns arbitrary vector perpendicular to input vector.
bool operator!=(const Int3D &i) const
Inequality test.
Definition: vec3d.hpp:322
Vec3D(std::istream &s)
Definition: vec3d.hpp:71
friend Vec3D cross(const Vec3D &vec1, const Vec3D &vec2)
Cross product.
Definition: vec3d.hpp:265
Bindary file writing and reading tools.
std::string to_string(const T &t)
Function for converting a type to string.
Definition: error.hpp:62
Vec3D & operator+=(const Vec3D &vec)
Vector accumulation
Definition: vec3d.hpp:101
double norm2(void) const
Returns 2-norm of vector.
Definition: vec3d.hpp:206
friend std::ostream & operator<<(std::ostream &os, const Vec3D &vec)
Outputting to stream.
Definition: vec3d.hpp:278
double & operator[](int i)
Definition: vec3d.hpp:78
bool approx(const Vec3D &x, double eps=1.0e-6) const
Approximate equality test.
void write_double(std::ostream &os, double value)
Write double value into stream os.
void save(std::ostream &s) const
Definition: vec3d.hpp:336
Vec3D operator-(const Vec3D &vec) const
Vector difference
Definition: vec3d.hpp:93
Vec3D & operator/=(double x)
Vector scaling with divisor.
Definition: vec3d.hpp:139
~Int3D()
Definition: vec3d.hpp:303
int32_t & operator()(int i)
Definition: vec3d.hpp:307
Int3D operator-(const Int3D &i)
Definition: vec3d.hpp:310
void save(std::ostream &os) const
Saves data to stream os.
Definition: vec3d.hpp:228
const int32_t & operator()(int i) const
Definition: vec3d.hpp:308
Int3D(int32_t i)
Definition: vec3d.hpp:295
Vec3D operator-(void) const
Unary minus.
Definition: vec3d.hpp:124
double operator*(const Vec3D &vec) const
Dot product.
Definition: vec3d.hpp:110
Vec3D & operator*=(double x)
Vector scaling.
Definition: vec3d.hpp:130
Homogenous vector for three dimensional space.
Definition: vec4d.hpp:67
bool operator==(const Int3D &i) const
Equality test.
Definition: vec3d.hpp:330
3D Integer vector class.
Definition: vec3d.hpp:289
Homogenous vectors for three dimensional space.
Vec3D(double x, double y, double z)
Definition: vec3d.hpp:67
Int3D(int32_t i, int32_t j, int32_t k)
Definition: vec3d.hpp:297
const double & operator()(int i) const
Definition: vec3d.hpp:81
int32_t read_int32(std::istream &is)
Read int32_t from stream is.
int32_t & operator[](int i)
Definition: vec3d.hpp:305
Vec3D(double x)
Definition: vec3d.hpp:65
friend std::ostream & operator<<(std::ostream &os, const Vec3D &vec)
Definition: vec3d.hpp:278
Vec3D operator*(double x) const
Vector scaling.
Definition: vec3d.hpp:118
Vec3D operator*(double x, const Vec3D &vec)
Definition: vec3d.hpp:272
~Vec3D()
Definition: vec3d.hpp:76
const double & operator[](int i) const
Definition: vec3d.hpp:79
Int3D(int32_t i, int32_t j)
Definition: vec3d.hpp:296
Int3D()
Definition: vec3d.hpp:294
Vec3D & operator=(const double &x)
Assignment of every coordinate.
Definition: vec3d.hpp:178
Three dimensional vector.
Definition: vec3d.hpp:58
double ssqr(void) const
Returns square of 2-norm of vector.
Definition: vec3d.hpp:214
bool operator==(const Vec3D &x) const
Equality test.
void abs(void)
Calculate absolute value of each component.
Definition: vec3d.hpp:187
double read_double(std::istream &is)
Readd double from stream is.
void normalize(void)
Normalize vector.
Definition: vec3d.hpp:195