From 0cf362840fee15e3fa47f3c4452007872ce4d2bf Mon Sep 17 00:00:00 2001 From: blobt Date: Thu, 11 Feb 2021 10:08:16 +0800 Subject: [PATCH] =?UTF-8?q?=E7=9B=B4=E7=BA=BF=E5=88=9D=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vs/3dMath/v15/.suo | Bin 38400 -> 37888 bytes GMath.cpp | 23 +++++++++++++++++++++++ GMath.h | 21 +++++++++++++++++++-- main.cpp | 14 ++++---------- 4 files changed, 46 insertions(+), 12 deletions(-) diff --git a/.vs/3dMath/v15/.suo b/.vs/3dMath/v15/.suo index c81a293870d600882399d8f1d98bec38c7d2f086..ba305557f9ad229369239bce88eae6d3cfc87875 100644 GIT binary patch delta 1925 zcmcgtUrbwN6z_L?FTE|dUFo0Ej?NWUSSgj=OBraw7FjEFP_|-NG$HEv=Vrpg;u_;{ z!6sW`GO8K(yl65LMIY2HnsFbDFFFS=hAAa3viO4WX)z`)rkd3m<~jHFPEhu?c#>bg z?>p!F^E>};^Ow2&hunoOCSKXUjbk3D=XSYnuYG=Mhh>!oEhurA;-=WA@H@9Gxp4g` z;vNbN#v)L%MvrbsMHQmDVsKW*KxM4O(T?ySyohx=jgrE-8&QMUhS-4!A;{Ja@2TF| zV;QldqJW#BNaGW@=tdkwBoThZlZZ5ePLZt74z8)(q$_{-yP+WZ5J8*n!y#DkDiuFy zV@u_b;fE~@H+Y}KSCr%^goTh$hm&4|3?JE9vF^q(jPM~O1bOrbjtvO7z^7P`aYC*k zhKCUJU>}aiZdG-p*d^$8c;OkxI9tCmm}IJy7AZWmjreFesmQk4M6onCK~B0MS~n@2 zSw4&kSn1deGH16FFP6nH`8Y*g9S)AeD{ye zccqzV!wdf*QCCpoixP#I!g60@D?tHwQ{eGQ+-KT;1tL;Wnqz%g^Or; zS}Xf(Ol?@uEm!+_xYKZ*kDRSVoGYqR~`R;z}`zscnn@;RmI* zBSz3SXDm@rWdV*J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_#YE(@%ku} z1-9|g zEN-74=xo|Bj^)u43<#gYjf-!?uR{{tzm$RSr2-T$jzQC4l)bcLe>wOuk2G=_V_sC) z{$NPrEf48O;Eg|VjztQ_YW&jGz0>=+&4wSa^ek=_T-U_>&!~xO`a!xG?AnQB?0p(ZQr^u>z@TwS(G|d`>$&g|9+RX$pimoo8BmKcyMYQuQ+N?l`gZt0U+&;UjP6A 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