Browse Source

直线完成

master
blobt 4 years ago
parent
commit
fe345cf7e8
  1. BIN
      .vs/3dMath/v15/.suo
  2. 12
      GMath.cpp
  3. 3
      GMath.h
  4. 14
      main.cpp

BIN
.vs/3dMath/v15/.suo

12
GMath.cpp

@ -1084,3 +1084,15 @@ GVector3 GLine::GetDir() const
{ {
return v; return v;
} }
bool GLine::IsOnLine(const GPoint3 & q)
{
return EQ_ZERO(dist(q, *this), PRECISION);
}
float dist(const GPoint3 & q, const GLine & l)
{
GVector3 u = q - l.p;
GVector3 p = proj(u, l.v);
return norm(u - p);
}

3
GMath.h

@ -222,4 +222,7 @@ public:
GVector3 GetPt() const; GVector3 GetPt() const;
GVector3 GetDir() const; GVector3 GetDir() const;
bool IsOnLine(const GPoint3& q);
friend float dist(const GPoint3& q, const GLine& l);
}; };

14
main.cpp

@ -2,15 +2,15 @@
int main() { int main() {
GLine l(GPoint3(0.0f, 0.0f, 0.0f), GVector3(1.0, 0.0f, 0.0f));
GLine l(GPoint3(0.0f, 0.0f, 0.0f), GVector3(1.0f, 0.0f, 0.0f));
GPoint3 q(0.0f, 0.0f, 1.0f);
GPoint3 p = l(2.0f);
float d = dist(q, l);
l.SetPt(GPoint3(0.0f, 0.0f, 1.0f));
l.SetDir(GVector3(1.0f, 0.0f, 0.0f));
cout << d << endl;
GPoint3 q = l(1.0f);
cout << q << endl;
bool b = l.IsOnLine(GPoint3(0.0f, 0.0f, 0.0f));
bool b2 = l.IsOnLine(GPoint3(0.5f, 0.0f, 0.0f));
bool b3 = l.IsOnLine(GPoint3(0.5f, 0.5f, 0.0f));
return 0; return 0;
} }
Loading…
Cancel
Save