73 Vec4D() { p[0] = 0.0; p[1] = 0.0; p[2] = 0.0; p[3] = 0.0; }
74 Vec4D(
double x ) { p[0] = x; p[1] = 0.0; p[2] = 0.0; p[3] = 0.0; }
75 Vec4D(
double x,
double y ) { p[0] = x; p[1] = y; p[2] = 0.0; p[3] = 0.0; }
76 Vec4D(
double x,
double y,
double z ) { p[0] = x; p[1] = y; p[2] = z; p[3] = 0.0; }
77 Vec4D(
double x,
double y,
double z,
double w ) { p[0] = x; p[1] = y; p[2] = z; p[3] = w; }
85 Vec4D( std::istream &s ) {
93 double &operator[](
int i ) {
return( p[i] ); }
94 const double &operator[](
int i )
const {
return( p[i] ); }
95 double &operator()(
int i ) {
return( p[i] ); }
96 const double &operator()(
int i )
const {
return( p[i] ); }
104 return(
Vec4D( p[0] + vec[0],
107 (p[2] == vec[2] ? 0.0 : 1.0) ) );
116 return(
Vec4D( p[0] - vec[0],
119 (p[2] == vec[2] ? 0.0 : 1.0) ) );
139 return( p[0] * vec[0] +
149 return(
Vec4D( x*p[0], x*p[1], x*p[2], p[3] ) );
180 if( p[0] != x.p[0] || p[1] != x.p[1] || p[2] != x.p[2] || p[3] != x.p[3] )
190 if( p[0] == x.p[0] && p[1] == x.p[1] && p[2] == x.p[2] && p[3] == x.p[3] )
211 double inv_w = 1.0/p[3];
223 double inv_norm = 1.0/sqrt( p[0]*p[0] + p[1]*p[1] + p[2]*p[2] );
235 return( sqrt( p[0]*p[0] + p[1]*p[1] + p[2]*p[2] ) );
243 return( p[0]*p[0] + p[1]*p[1] + p[2]*p[2] );
246 void save( std::ostream &s )
const {
276 return( vec.
norm2() );
280 return(
Vec4D( vec1[1] * vec2[2] - vec1[2] * vec2[1],
281 vec1[2] * vec2[0] - vec1[0] * vec2[2],
282 vec1[0] * vec2[1] - vec1[1] * vec2[0],
289 return(
Vec4D( x*vec[0], x*vec[1], x*vec[2], vec[3] ) );
293 inline std::ostream &operator<<( std::ostream &os,
const Vec4D &vec )
295 os << std::setw(12) <<
to_string(vec[0]).substr(0,12) <<
" ";
296 os << std::setw(12) <<
to_string(vec[1]).substr(0,12) <<
" ";
297 os << std::setw(12) <<
to_string(vec[2]).substr(0,12) <<
" ";
298 os << std::setw(12) <<
to_string(vec[3]).substr(0,12);
Three dimensional vector.
Definition: vec3d.hpp:58
Homogenous vector for three dimensional space.
Definition: vec4d.hpp:67
bool operator==(const Vec4D &x)
Equality test.
Definition: vec4d.hpp:189
double operator*(const Vec4D &vec) const
Dot product.
Definition: vec4d.hpp:138
Vec4D & operator/=(double x)
Vector scaling with divisor.
Definition: vec4d.hpp:167
Vec4D & operator*=(double x)
Vector scaling.
Definition: vec4d.hpp:156
Vec4D & operator+=(const Vec4D &vec)
Accumulation.
Definition: vec4d.hpp:127
friend Vec4D cross(const Vec4D &vec1, const Vec4D &vec2)
Cross product.
Definition: vec4d.hpp:279
void normalize()
Normalize vector.
Definition: vec4d.hpp:222
bool operator!=(const Vec4D &x)
Inequality test.
Definition: vec4d.hpp:179
double ssqr() const
Returns square of 2-norm of vector.
Definition: vec4d.hpp:242
Vec4D & operator=(const Vec4D &x)
Assignment.
Definition: vec4d.hpp:197
Vec4D operator*(double x) const
Vector scaling.
Definition: vec4d.hpp:148
double norm2() const
Returns 2-norm of vector.
Definition: vec4d.hpp:234
friend std::ostream & operator<<(std::ostream &os, const Vec4D &vec)
Outputting to stream.
Definition: vec4d.hpp:293
Vec4D operator-(const Vec4D &vec) const
Difference.
Definition: vec4d.hpp:115
Vec4D operator+(const Vec4D &vec) const
Addition.
Definition: vec4d.hpp:103
void homogenize()
Homogenize vector.
Definition: vec4d.hpp:210
Error classes and handling
std::string to_string(const T &t)
Function for converting a type to string.
Definition: error.hpp:62
void write_double(std::ostream &s, double value)
Write double value into stream os.
Definition: file.cpp:88
double read_double(std::istream &s)
Readd double from stream is.
Definition: file.cpp:157
Bindary file writing and reading tools.
double norm2(const Vector &vec)
Definition: mvector.cpp:474
Three dimensional vectors.
Vec4D operator*(double x, const Vec4D &vec)
Definition: vec4d.hpp:287
Vec4D cross(const Vec4D &vec1, const Vec4D &vec2)
Definition: vec4d.hpp:279