Browse Source

点类基础函数

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

BIN
.vs/3dMath/v15/.suo

38
GMath.cpp

@ -1095,4 +1095,40 @@ float dist(const GPoint3 & q, const GLine & l)
GVector3 u = q - l.p;
GVector3 p = proj(u, l.v);
return norm(u - p);
}
}
GPlane::GPlane(const GVector3 & _n, const GPoint3 & _p)
{
n = _n;
d = -n * _p;
}
GPlane::GPlane(const GPoint3 & p1, const GPoint3 & p2, const GPoint3 & p3)
{
n = (p2 - p1) ^ (p3 - p1);
d = -n * p1; //是平面上的一点点乘法线再取负号
}
GPlane::GPlane(const float & a, const float & b, const float & c, const float & d)
{
n = GVector3(a, b, c);
this->d = d;
}
GPlane::GPlane(const GPlane & copy)
{
n = copy.n;
d = copy.d;
}
GPlane& GPlane::operator=(const GPlane & rhs)
{
n = rhs.n;
d = rhs.d;
return *this;
}
GVector3 GPlane::GetNormal() const
{
return n;
}

16
GMath.h

@ -21,6 +21,7 @@ using namespace std;
class GVector3;
class GVector;
class GMatrix;
class GPlane;
typedef GVector3 GPoint3;
class GVector3 {
@ -225,4 +226,19 @@ public:
bool IsOnLine(const GPoint3& q);
friend float dist(const GPoint3& q, const GLine& l);
};
class GPlane {
private:
//ax+by+cz+d=0 a b c 线d是平面上的一点点乘法线再取负号
GVector3 n;
float d;
public:
GPlane(const GVector3& _n = GVector3(0.0f, 0.0f, 0.0f), const GPoint3& _p = GVector3(0.0f, 0.0f, 0.0f));
GPlane(const GPoint3& p1, const GPoint3& p2, const GPoint3& p3);
GPlane(const float& a, const float& b, const float&c, const float& d);
GPlane(const GPlane& copy);
GPlane& operator =(const GPlane& rhs);
GVector3 GetNormal() const;
};

12
main.cpp

@ -2,15 +2,11 @@
int main() {
GLine l(GPoint3(0.0f, 0.0f, 0.0f), GVector3(1.0f, 0.0f, 0.0f));
GPoint3 q(0.0f, 0.0f, 1.0f);
GPlane PI1(GVector3(0.0f, 0.0f, 1.0f), GPoint3(0.0f, 0.0f, 0.0f));
GPlane PI2(GPoint3(1.0,0.0f,0.0f), GPoint3(0.0, 1.0f, 0.0f), GPoint3(0.0, 0.0f, 1.0f));
float d = dist(q, l);
GPlane PI = PI1;
cout << PI.GetNormal() << endl;
cout << d << 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;
}
Loading…
Cancel
Save