From ad3ddb0be7923692bd5c91186193583c3953884e Mon Sep 17 00:00:00 2001 From: blobt Date: Fri, 12 Feb 2021 10:17:16 +0800 Subject: [PATCH] =?UTF-8?q?=E7=82=B9=E7=B1=BB=E5=9F=BA=E7=A1=80=E5=87=BD?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vs/3dMath/v15/.suo | Bin 38912 -> 36864 bytes GMath.cpp | 38 +++++++++++++++++++++++++++++++++++++- GMath.h | 16 ++++++++++++++++ main.cpp | 12 ++++-------- 4 files changed, 57 insertions(+), 9 deletions(-) diff --git a/.vs/3dMath/v15/.suo b/.vs/3dMath/v15/.suo index e36491f91230e60016829fbc714742445eff0651..521fac9d27acb147025742b7cf0ef17b49cf151e 100644 GIT binary patch delta 2062 zcmbtVZ%kWN6z_fX&ntUf%NS7kGs;^2Z0q3ll>uQhfUSW1Ysr|?n2izaHcS`Py(JQG zV~KGpY=fReKNyo`@ypa?o6qP++(2XYVYme4gHdB*vV;!~mp3w&ta{FCUwKTvEZ*eT zd+s@>_ndpq@7_0ljT^tjP3>dC^=F+Nb3hqa>iF^F#lQYEEwX1!CQ~zvaHH%RJh09S z|KO-Z9nH`y`9RI8IY?Sj6Bs*~C5jhAktt-U22vLmK z4sVzX;61+9QGlxeLPE5nHo}tAy>}B_7uy1NIFC^G;n$RD9hxcA4hUrhC|j-vX1M^! zS$+I&v{BGh#x@W0(C%yx{^pj|rj6tfG|04m0oSGEm19Q9jmSl8L%2}eW-mi&6Cw#e znVU-5P@;de<4jq1AUY9U2+Vmtk?kw{0Obk9B_dPboN(f{;=orhD7t4|R{;k3U@Bnm@RIFJk9VZ*SxHNsQtGqL2nh(lZH z{iT%H`^tl&{S5BJy&!USkV~R4$B7m?a{yLrI)!SKTgAd?&MN6(mY%ZqSYfrw+e9%Oe^pk@+5GfLGxugsP* zCeRktRNbPe9)TsKc7D6AWWg$UOX?DcQ$*l3PYFH6u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VFj4F1L4(o|6IdN0n+nc? zboeW{%!NS;_t~iQx=~P`jhn>6^HTkE*44F+pv-Dekn??}CX*Uaw<;?ec?L`jS|Vbz z7>+=l7-ta}7oRc~8yKc3G#6o+M-~OP8Bf&|oCKvVZld|R6OXhd&QsG;lk4`))P@Gg zxqEmg!Zf402qaIwxDOP9iYKj|Ip*y#(QNDX&48P7$W_N|^dx9zYT+e+FTVu=efIM` z;>RBGcdgd!5e#8eEsR4}P&Hdi{k;`M`i$i}Bs5c4MlXj7M5&QOiKC;^p!D2W^ufj* za!J!~EYomlUFF>x=P9bc+|w4p7C9VWcisDJg%f6Z8|@7kU?tRTq7d|ifmDZ0ieveo zREp~Vx0UJ^)Bz|gfkiEsL0;LshvfqcO_!{ZIBWJrmmOTOZYIcsvG=TSqW@K}_orp+ zfty?rS)|74n1HGMdthO}ESBD#-`)D6QeJT#Nk?^(mFggc6?kE=eBd1 zWQ${Y;+=1YaxKBelV@M%YkoKaXHp(Gm^|QUN(=0}D{mQIO9n4g1&o{~@WS7U`#Ln|x_pFGq0f96P* KhI@_o-1sMbSL71_ diff --git a/GMath.cpp b/GMath.cpp index ff5810d..4264ba8 100644 --- a/GMath.cpp +++ b/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); -} \ No newline at end of file +} + +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; +} diff --git a/GMath.h b/GMath.h index 8d7efd2..72a6879 100644 --- a/GMath.h +++ b/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; }; \ No newline at end of file diff --git a/main.cpp b/main.cpp index cad1ad6..055bc8f 100644 --- a/main.cpp +++ b/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; } \ No newline at end of file