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; }
90 const double &
operator[](
int i )
const {
return( p[i] ); }
92 const double &
operator()(
int i )
const {
return( p[i] ); }
100 return(
Vec4D( p[0] + vec[0],
103 (p[2] == vec[2] ? 0.0 : 1.0) ) );
112 return(
Vec4D( p[0] - vec[0],
115 (p[2] == vec[2] ? 0.0 : 1.0) ) );
135 return( p[0] * vec[0] +
145 return(
Vec4D( x*p[0], x*p[1], x*p[2], p[3] ) );
176 if( p[0] != x.p[0] || p[1] != x.p[1] || p[2] != x.p[2] || p[3] != x.p[3] )
186 if( p[0] == x.p[0] && p[1] == x.p[1] && p[2] == x.p[2] && p[3] == x.p[3] )
207 double inv_w = 1.0/p[3];
219 double inv_norm = 1.0/sqrt( p[0]*p[0] + p[1]*p[1] + p[2]*p[2] );
231 return( sqrt( p[0]*p[0] + p[1]*p[1] + p[2]*p[2] ) );
239 return( p[0]*p[0] + p[1]*p[1] + p[2]*p[2] );
242 void save( std::ostream &s )
const {
272 return( vec.
norm2() );
276 return(
Vec4D( vec1[1] * vec2[2] - vec1[2] * vec2[1],
277 vec1[2] * vec2[0] - vec1[0] * vec2[2],
278 vec1[0] * vec2[1] - vec1[1] * vec2[0],
285 return(
Vec4D( x*vec[0], x*vec[1], x*vec[2], vec[3] ) );
291 os << std::setw(12) <<
to_string(vec[0]).substr(0,12) <<
" ";
292 os << std::setw(12) <<
to_string(vec[1]).substr(0,12) <<
" ";
293 os << std::setw(12) <<
to_string(vec[2]).substr(0,12) <<
" ";
294 os << std::setw(12) <<
to_string(vec[3]).substr(0,12);
Vec4D operator+(const Vec4D &vec) const
Addition.
Definition: vec4d.hpp:99
void homogenize()
Homogenize vector.
Definition: vec4d.hpp:206
Vec4D operator*(double x) const
Vector scaling.
Definition: vec4d.hpp:144
Vec3D cross(const Vec3D &vec1, const Vec3D &vec2)
Definition: vec3d.hpp:265
const double & operator()(int i) const
Definition: vec4d.hpp:92
Vec4D(double x)
Definition: vec4d.hpp:74
Vec4D(double x, double y, double z)
Definition: vec4d.hpp:76
double norm2(const Vec3D &vec)
Definition: vec3d.hpp:260
double & operator()(int i)
Definition: vec4d.hpp:91
double & operator[](int i)
Definition: vec4d.hpp:89
Vec4D & operator/=(double x)
Vector scaling with divisor.
Definition: vec4d.hpp:163
Bindary file writing and reading tools.
double operator*(const Vec4D &vec) const
Dot product.
Definition: vec4d.hpp:134
std::string to_string(const T &t)
Function for converting a type to string.
Definition: error.hpp:62
~Vec4D()
Definition: vec4d.hpp:87
const double & operator[](int i) const
Definition: vec4d.hpp:90
Three dimensional vectors.
Vec4D(std::istream &s)
Definition: vec4d.hpp:81
double ssqr() const
Returns square of 2-norm of vector.
Definition: vec4d.hpp:238
friend Vec4D cross(const Vec4D &vec1, const Vec4D &vec2)
Cross product.
Definition: vec4d.hpp:275
void write_double(std::ostream &os, double value)
Write double value into stream os.
bool operator!=(const Vec4D &x)
Inequality test.
Definition: vec4d.hpp:175
double norm2() const
Returns 2-norm of vector.
Definition: vec4d.hpp:230
Vec4D & operator=(const Vec4D &x)
Assignment.
Definition: vec4d.hpp:193
Vec4D & operator+=(const Vec4D &vec)
Accumulation.
Definition: vec4d.hpp:123
void normalize()
Normalize vector.
Definition: vec4d.hpp:218
Vec4D(double x, double y, double z, double w)
Definition: vec4d.hpp:77
Color operator*(double x, const Color &c)
Definition: color.hpp:116
bool operator==(const Vec4D &x)
Equality test.
Definition: vec4d.hpp:185
Homogenous vector for three dimensional space.
Definition: vec4d.hpp:67
Error classes and handling
Vec4D & operator*=(double x)
Vector scaling.
Definition: vec4d.hpp:152
Vec4D()
Definition: vec4d.hpp:73
Vec4D operator-(const Vec4D &vec) const
Difference.
Definition: vec4d.hpp:111
std::ostream & operator<<(std::ostream &os, const Color &c)
Definition: color.hpp:122
friend std::ostream & operator<<(std::ostream &os, const Vec4D &vec)
Outputting to stream.
Definition: vec4d.hpp:289
Three dimensional vector.
Definition: vec3d.hpp:58
void save(std::ostream &s) const
Definition: vec4d.hpp:242
double read_double(std::istream &is)
Readd double from stream is.
Vec4D(double x, double y)
Definition: vec4d.hpp:75