Browse Source

直线初步

master
blobt 4 years ago
parent
commit
0cf362840f
  1. BIN
      .vs/3dMath/v15/.suo
  2. 23
      GMath.cpp
  3. 21
      GMath.h
  4. 14
      main.cpp

BIN
.vs/3dMath/v15/.suo

23
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;
}

21
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;
};

14
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;
}
Loading…
Cancel
Save