diff --git a/.vs/3dMath/v15/.suo b/.vs/3dMath/v15/.suo index c81a293..ba30555 100644 Binary files a/.vs/3dMath/v15/.suo and b/.vs/3dMath/v15/.suo differ diff --git a/GMath.cpp b/GMath.cpp index e8f164f..7d09e3a 100644 --- a/GMath.cpp +++ b/GMath.cpp @@ -1039,3 +1039,26 @@ float Det(const GMatrix & m) return ret; } +GLine::GLine(const GPoint3 & _p, const GVector3 & _v) +{ + p = _p; + v = _v; +} + +GLine::GLine(const GLine & copy) +{ + p = copy.p; + v = copy.v; +} + +GLine & GLine::operator=(const GLine & rhs) +{ + p = rhs.p; + v = rhs.v; + return *this; +} + +GPoint3 GLine::operator()(const float t) const +{ + return p + v*t; +} diff --git a/GMath.h b/GMath.h index f18bfa5..9dc7475 100644 --- a/GMath.h +++ b/GMath.h @@ -18,6 +18,11 @@ using namespace std; +class GVector3; +class GVector; +class GMatrix; +typedef GVector3 GPoint3; + class GVector3 { private: float v[3]; @@ -74,7 +79,6 @@ public: const float operator [](const int& idx) const;//下标获取分量 }; -class GMatrix; class GVector { public: //GVector 1~2 @@ -192,11 +196,24 @@ public: friend int Rank(const GMatrix& m);//获取矩阵的秩 friend int Nullity(const GMatrix& m);//获取矩阵的零化度 - friend GMatrix Mij(const GMatrix& m, int r, int c); //计算余子式 + friend GMatrix Mij(const GMatrix& m, int r, int c); //计算余子式矩阵 friend float Det(const GMatrix& m); private: int r; int c; float *m; +}; + +class GLine { +private: + // l(t) = p + t*v; + GPoint3 p;//端点 + GVector3 v;//方向 +public: + GLine(const GPoint3& _p = GPoint3(0.0f, 0.0f, 0.0f), const GVector3& _v = GVector3(0.0f, 0.0f, 0.0f)); + GLine(const GLine& copy); + + GLine& operator =(const GLine& rhs); + GPoint3 operator ()(const float t) const; }; \ No newline at end of file diff --git a/main.cpp b/main.cpp index 4c5d295..720e3a7 100644 --- a/main.cpp +++ b/main.cpp @@ -2,16 +2,10 @@ int main() { - float f1[] = { - 1.0f, 4.0f, -8.0, - 0.0f, 2.0f, 9.0, - 0.0f, 6.0f, 1.0f - }; - - GMatrix M1(3,3, f1); - cout << M1 << endl; - - cout << Det(M1) << endl; + GLine l(GPoint3(0.0f, 0.0f, 0.0f), GVector3(1.0, 0.0f, 0.0f)); + GPoint3 p = l(2.0f); + + cout << p << endl; return 0; } \ No newline at end of file