diff --git a/.vs/3dMath/v15/.suo b/.vs/3dMath/v15/.suo index 7e1982f..e36491f 100644 Binary files a/.vs/3dMath/v15/.suo and b/.vs/3dMath/v15/.suo differ diff --git a/GMath.cpp b/GMath.cpp index dd8b1d9..ff5810d 100644 --- a/GMath.cpp +++ b/GMath.cpp @@ -1084,3 +1084,15 @@ GVector3 GLine::GetDir() const { 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); +} \ No newline at end of file diff --git a/GMath.h b/GMath.h index ff9532a..8d7efd2 100644 --- a/GMath.h +++ b/GMath.h @@ -222,4 +222,7 @@ public: GVector3 GetPt() const; GVector3 GetDir() const; + + bool IsOnLine(const GPoint3& q); + friend float dist(const GPoint3& q, const GLine& l); }; \ No newline at end of file diff --git a/main.cpp b/main.cpp index d004704..cad1ad6 100644 --- a/main.cpp +++ b/main.cpp @@ -2,15 +2,15 @@ int main() { - GLine l(GPoint3(0.0f, 0.0f, 0.0f), GVector3(1.0, 0.0f, 0.0f)); - - GPoint3 p = l(2.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); - l.SetPt(GPoint3(0.0f, 0.0f, 1.0f)); - l.SetDir(GVector3(1.0f, 0.0f, 0.0f)); + float d = dist(q, l); - GPoint3 q = l(1.0f); + cout << d << endl; - 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; } \ No newline at end of file