📄 geom.h
字号:
value_type component[N_row][N_col]; };/* ####################### # class Square_matrix # #######################*/ template<int N,typename Real> class Square_matrix:public Matrix<N,N,Real>{ public: //! Used type. typedef Real value_type; //@{ //! Classical constructor. inline Square_matrix(); explicit inline Square_matrix(const value_type tab[N][N]); inline Square_matrix(const Matrix<N,N,Real>& m); //@} inline value_type trace() const; //! Identity matrix. static inline Square_matrix<N,Real> identity(); };/* ########################## # Out of class functions # ##########################*///@{//! Classical operator. template<int N,typename Real> inline Vec<N,Real> operator+(const Vec<N,Real>& v1, const Vec<N,Real>& v2); template<int N,typename Real> inline Vec<N,Real> operator-(const Vec<N,Real>& v1, const Vec<N,Real>& v2); template<int N,typename Real> inline Vec<N,Real> operator*(const Vec<N,Real>& v, const typename Vec<N,Real>::value_type r); template<int N,typename Real> inline Vec<N,Real> operator*(const typename Vec<N,Real>::value_type r, const Vec<N,Real>& v); template<int N,typename Real> inline Vec<N,Real> operator/(const Vec<N,Real>& v, const typename Vec<N,Real>::value_type r);//@}/* ############################################# ############################################# ############################################# ###### ###### ###### I M P L E M E N T A T I O N ###### ###### ###### ############################################# ############################################# ############################################# *//* ############# # class Vec # #############*/ template<int N,typename Real> Vec<N,Real>::Vec(){ for(int i=0;i<N;i++){ coordinate[i] = Real(); } } template<int N,typename Real> Vec<N,Real>::Vec(const value_type tab[N]){ for(int i=0;i<N;i++){ coordinate[i] = tab[i]; } }/*! No size check.*/ template<int N,typename Real> Vec<N,Real>::Vec(const std::vector<value_type>& tab){ for(int i=0;i<N;i++){ coordinate[i] = tab[i]; } } template<int N,typename Real> Vec<N,Real>::Vec(const Vec<N,Real>& v){ for(int i=0;i<N;i++){ coordinate[i] = v.coordinate[i]; } } template<int N,typename Real> const typename Vec<N,Real>::value_type& Vec<N,Real>::operator[](const int i) const{ return coordinate[i]; } template<int N,typename Real> typename Vec<N,Real>::value_type& Vec<N,Real>::operator[](const int i){ return coordinate[i]; } template<int N,typename Real> typename Vec<N,Real>::value_type Vec<N,Real>::norm() const{ return sqrt(square_norm()); } template<int N,typename Real> typename Vec<N,Real>::value_type Vec<N,Real>::square_norm() const{ return (*this)*(*this); } template<int N,typename Real> Vec<N,Real>& Vec<N,Real>::normalize(){ const value_type n = norm(); if (n != 0){ for(int i = 0;i < N;++i){ coordinate[i] /= n; } } return *this; } template<int N,typename Real> inline Vec<N,Real> Vec<N,Real>::unit() const{ return Vec<N,Real>(*this).normalize(); } template<int N,typename Real> inline Matrix<N,1,Real> Vec<N,Real>::column_matrix() const{ Matrix<N,1,Real> m; for(int i = 0;i < N;++i){ m(i,0) = coordinate[i]; } return m; } template<int N,typename Real> Vec<N,Real>& Vec<N,Real>::operator=(const Vec<N,Real>& v){ if (this!=&v) { for(int i=0;i<N;i++){ coordinate[i] = v.coordinate[i]; } } return *this; } template<int N,typename Real> bool Vec<N,Real>::operator==(const Vec<N,Real>& v) const{ for(int i=0;i<N;i++){ if (coordinate[i]!=v.coordinate[i]){ return false; } } return true; } template<int N,typename Real> bool Vec<N,Real>::operator!=(const Vec<N,Real>& v) const{ return !(*this==v); } template<int N,typename Real> Vec<N,Real>& Vec<N,Real>::operator+=(const Vec<N,Real>& v){ for(int i=0;i<N;i++){ coordinate[i] += v.coordinate[i]; } return *this; } template<int N,typename Real> Vec<N,Real>& Vec<N,Real>::operator-=(const Vec<N,Real>& v){ for(int i=0;i<N;i++){ coordinate[i] -= v.coordinate[i]; } return *this; } template<int N,typename Real> Vec<N,Real>& Vec<N,Real>::operator*=(const value_type r){ for(int i=0;i<N;i++){ coordinate[i] *= r; } return *this; }/*! No check for r<>0 .*/ template<int N,typename Real> Vec<N,Real>& Vec<N,Real>::operator/=(const value_type r){ for(int i=0;i<N;i++){ coordinate[i] /= r; } return *this; } template<int N,typename Real> Vec<N,Real> Vec<N,Real>::operator-() const{ Vec<N,Real> res; for(int i=0;i<N;i++){ res.coordinate[i] = -coordinate[i]; } return res; }/* ############## # class Vec2 # ##############*/ template<typename Real> Vec2<Real>::Vec2() :Vec<2,Real>(){} template<typename Real> Vec2<Real>::Vec2(const value_type tab[2]) :Vec<2,Real>(tab){} template<typename Real> Vec2<Real>::Vec2(const std::vector<value_type>& tab) :Vec<2,Real>(tab){} template<typename Real> Vec2<Real>::Vec2(const Vec<2,Real>& v) :Vec<2,Real>(v){} template<typename Real> Vec2<Real>::Vec2(const value_type x,const value_type y) :Vec<2,Real>(){ (*this)[0] = x; (*this)[1] = y; } template<typename Real> const typename Vec2<Real>::value_type& Vec2<Real>::x() const{ return (*this)[0]; } template<typename Real> typename Vec2<Real>::value_type& Vec2<Real>::x(){ return (*this)[0]; } template<typename Real> const typename Vec2<Real>::value_type& Vec2<Real>::y() const{ return (*this)[1]; } template<typename Real> typename Vec2<Real>::value_type& Vec2<Real>::y(){ return (*this)[1]; }/* ############## # class Vec3 # ##############*/ template<typename Real> Vec3<Real>::Vec3() :Vec<3,Real>(){} template<typename Real> Vec3<Real>::Vec3(const value_type tab[3]) :Vec<3,Real>(tab){} template<typename Real> Vec3<Real>::Vec3(const std::vector<value_type>& tab) :Vec<3,Real>(tab){} template<typename Real> Vec3<Real>::Vec3(const Vec<3,Real>& v) :Vec<3,Real>(v){} template<typename Real> Vec3<Real>::Vec3(const value_type x,const value_type y,const value_type z) :Vec<3,Real>(){ (*this)[0] = x; (*this)[1] = y; (*this)[2] = z; } template<typename Real> Vec3<Real>::Vec3(const Vec2<Real>& v,const value_type z) :Vec<3,Real>(){ (*this)[0] = v.x(); (*this)[1] = v.y(); (*this)[2] = z; } template<typename Real> Vec3<Real>::Vec3(const Hvec3<Real>& v) :Vec<3,Real>(){ (*this)[0] = v.x(); (*this)[1] = v.y(); (*this)[2] = v.z(); } template<typename Real> const typename Vec3<Real>::value_type& Vec3<Real>::x() const{ return (*this)[0]; } template<typename Real> typename Vec3<Real>::value_type& Vec3<Real>::x(){ return (*this)[0]; } template<typename Real> const typename Vec3<Real>::value_type& Vec3<Real>::y() const{ return (*this)[1]; } template<typename Real> typename Vec3<Real>::value_type& Vec3<Real>::y(){ return (*this)[1]; } template<typename Real> const typename Vec3<Real>::value_type& Vec3<Real>::z() const{ return (*this)[2]; } template<typename Real> typename Vec3<Real>::value_type& Vec3<Real>::z(){ return (*this)[2]; }/* ############### # class Hvec2 # ###############*/ template<typename Real> Hvec2<Real>::Hvec2() :Vec<3,Real>(){} template<typename Real> Hvec2<Real>::Hvec2(const value_type tab[3]) :Vec<3,Real>(tab){} template<typename Real> Hvec2<Real>::Hvec2(const std::vector<value_type>& tab) :Vec<3,Real>(tab){} template<typename Real> Hvec2<Real>::Hvec2(const Vec<3,Real>& v) :Vec<3,Real>(v){} //@{/*! \e (sx,sy,sz,s) are directly given and not \e (x,y,z).*/ template<typename Real> Hvec2<Real>::Hvec2(const value_type sx, const value_type sy, const value_type s) :Vec<4,Real>(){ (*this)[0] = sx; (*this)[1] = sy; (*this)[2] = s; } template<typename Real> Hvec2<Real>::Hvec2(const Vec2<Real>& sv,const value_type s) :Vec<3,Real>(){ (*this)[0] = sv.x(); (*this)[1] = sv.y(); (*this)[2] = s; }//@} template<typename Real> const typename Hvec2<Real>::value_type& Hvec2<Real>::sx() const{ return (*this)[0]; } template<typename Real> typename Hvec2<Real>::value_type& Hvec2<Real>::sx(){ return (*this)[0]; } template<typename Real> const typename Hvec2<Real>::value_type& Hvec2<Real>::sy() const{ return (*this)[1]; } template<typename Real> typename Hvec2<Real>::value_type& Hvec2<Real>::sy(){ return (*this)[1]; } template<typename Real> const typename Hvec2<Real>::value_type& Hvec2<Real>::s() const{ return (*this)[2]; } template<typename Real> typename Hvec2<Real>::value_type& Hvec2<Real>::s(){ return (*this)[2]; } template<typename Real> typename Hvec2<Real>::value_type Hvec2<Real>::x() const{ return ((*this)[0]/(*this)[2]); } template<typename Real> typename Hvec2<Real>::value_type Hvec2<Real>::y() const{ return ((*this)[1]/(*this)[2]); }/* ############### # class Hvec3 # ###############*/ template<typename Real> Hvec3<Real>::Hvec3() :Vec<4,Real>(){} template<typename Real> Hvec3<Real>::Hvec3(const value_type tab[4]) :Vec<4,Real>(tab){} template<typename Real> Hvec3<Real>::Hvec3(const std::vector<value_type>& tab) :Vec<4,Real>(tab){} template<typename Real> Hvec3<Real>::Hvec3(const Vec<4,Real>& v) :Vec<4,Real>(v){} //@{/*! \e (sx,sy,sz,s) are directly goven and not \e (x,y,z).*/ template<typename Real> Hvec3<Real>::Hvec3(const value_type sx, const value_type sy, const value_type sz, const value_type s) :Vec<4,Real>(){ (*this)[0] = sx; (*this)[1] = sy; (*this)[2] = sz; (*this)[3] = s; } template<typename Real> Hvec3<Real>::Hvec3(const Vec2<Real>& sv,const value_type sz,const value_type s) :Vec<4,Real>(){ (*this)[0] = sv.x(); (*this)[1] = sv.y(); (*this)[2] = sz; (*this)[3] = s; } template<typename Real>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -