{"id":4177,"date":"2018-06-22T22:14:39","date_gmt":"2018-06-22T14:14:39","guid":{"rendered":"http:\/\/www.bookcard.net\/wordpress\/?p=4177"},"modified":"2018-06-22T22:14:39","modified_gmt":"2018-06-22T14:14:39","slug":"game_model_plane","status":"publish","type":"post","link":"https:\/\/www.bookcard.net\/wordpress\/game_model_plane\/","title":{"rendered":"\u904a\u6232\u5efa\u6a21-\u5e73\u9762\u78b0\u649e"},"content":{"rendered":"<figure id=\"attachment_4178\" aria-describedby=\"caption-attachment-4178\" style=\"width: 1024px\" class=\"wp-caption alignnone\"><a href=\"https:\/\/www.bookcard.net\/wordpress\/wp-content\/uploads\/2018\/06\/GAME_MODEL_PLANE.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-4178\" src=\"https:\/\/www.bookcard.net\/wordpress\/wp-content\/uploads\/2018\/06\/GAME_MODEL_PLANE.jpg\" alt=\"\" width=\"1024\" height=\"768\" srcset=\"https:\/\/www.bookcard.net\/wordpress\/wp-content\/uploads\/2018\/06\/GAME_MODEL_PLANE.jpg 1024w, https:\/\/www.bookcard.net\/wordpress\/wp-content\/uploads\/2018\/06\/GAME_MODEL_PLANE-300x225.jpg 300w, https:\/\/www.bookcard.net\/wordpress\/wp-content\/uploads\/2018\/06\/GAME_MODEL_PLANE-768x576.jpg 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption id=\"caption-attachment-4178\" class=\"wp-caption-text\">\u904a\u6232\u5efa\u6a21-\u5e73\u9762\u78b0\u649e<\/figcaption><\/figure>\n<p>\u5e73\u9762\u662f3D\u5716\u5f62\u5b78\u91cd\u8981\u90e8\u5206.\u5e73\u9762\u6709\u5169\u500b\u91cd\u8981\u6982\u5ff5.<\/p>\n<p>1.3D\u5e73\u9762\u90fd\u7121\u7aae\u9060\u5ef6\u4f38<\/p>\n<p>2.\u6240\u6709\u5e73\u9762\u90fd\u5c07\u6574\u500b\u7a7a\u9593\u5206\u6210\u5169\u500b\u534a\u7a7a\u9593.\u6b63\u534a\u7a7a\u9593\u70ba\u6cd5\u7dda\u6307\u5411\u7a7a\u9593,\u8ca0\u534a\u7a7a\u9593\u5247\u662f\u4ee4\u4e00\u5247\u7a7a\u9593.\u9019\u500b\u7279\u6027\u5c0d\u65bc\u78b0\u649e\u7b97\u6cd5\u91cd\u8981<\/p>\n<p>\u5e73\u9762\u63cf\u6558\u5982\u4e0b:<\/p>\n<p>\u5e73\u9762\u6cd5\u7dda\u5411\u91cf:n=(a,b,c)<\/p>\n<p>\u5e73\u9762\u4efb\u610f\u9ede:p0=(x0,y0,z0)<\/p>\n<p>\u5e73\u9762\u4efb\u610f\u9ede:p=(x,y,z)<\/p>\n<p>\u5e73\u9762\u8207\u539f\u9ede\u8ddd\u96e2:d\u5e73\u9762\u4f4d\u79fb\u5e38\u91cf(plane-shift constant)<\/p>\n<p>\u56e0\u70ba\u6cd5\u7ddan\u8207\u5411\u91cf(p0-&gt;p)\u5782\u76f4. \u56e0\u5169\u5782\u76f4\u5411\u91cf\u9ede\u7a4d\u70ba\u96f6:<\/p>\n<p>n * (p0-&gt;p) = 0<\/p>\n<p>\u8f49\u70ba\u5206\u91cf\u8868\u793a<\/p>\n<p>(a,b,c)*(x-x0,y-y0,z-z0)=0<\/p>\n<p>\u8f49\u70ba\u300e\u9802\u9ede\u300f\u8207\u300e\u6cd5\u7dda\u300f\u8868\u793a<\/p>\n<p>a<em>(x-x0)+b<\/em>(y-y0)+c*(z-z0)=0<\/p>\n<p>a<em>x+b<\/em>y+c<em>z+(-a<\/em>x0-b<em>y0-c<\/em>z0)=0<\/p>\n<p>\u4ee4d=-a<em>x0-b<\/em>y0-c*z0<\/p>\n<p>\u300e\u5e73\u9762\u65b9\u7a0b\u300f\u5982\u4e0b:<\/p>\n<p>a<em>x+b<\/em>y+c*z+d=0<\/p>\n<p>&nbsp;<\/p>\n<p>\u9019\u8db3\u4ee5\u5b9a\u7fa9\u5e73\u9762\u7d50\u69cb<\/p>\n<p>typedef struct PLANE3D_TYP{<\/p>\n<p>VECTOR3D n;\/\/\u5e73\u9762\u6cd5\u7dda\u5411\u91cf(\u4e0d\u5fc5\u662f\u55ae\u4f4d\u5411\u91cf)<\/p>\n<p>float dist;\/\/\u5e73\u9762\u5230\u539f\u9ede\u6700\u8fd1\u8ddd\u96e2<\/p>\n<p>POINT3D p0;\/\/\u5e73\u9762\u4e0a\u6700\u8fd1\u539f\u9ede\u7684\u9ede<\/p>\n<p>}PLANE3D,*PLANE3D_PTR;<\/p>\n<p>&nbsp;<\/p>\n<p>\u5224\u65b7\u300e\u9ede\u300f\u4f4d\u65bc\u300e\u5e73\u9762\u300f\u90a3\u500b\u534a\u7a7a<\/p>\n<p>3D\u4e16\u754c\u4e2d\u300e\u8996\u9ede\u300f\u3001\u300e\u89d2\u8272\u300f\u4e26\u4e0d\u80fd\u7a7f\u8d8a\u7246\u58c1.\u8981\u505a\u5230\u9019\u6b65\u9700\u5224\u65b7\u9ede\u4f4d\u65bc\u5e73\u6b63\u7a7a\u9593(\u6cd5\u7dda\u6307\u5411)\u9084\u662f\u8ca0\u7a7a\u9593.<\/p>\n<p>\u8981\u5224\u65b7\u9019\u9ede\u9700\u8981\u4e0b\u9762\u7684\u5e73\u9762\u65b9\u7a0b<\/p>\n<p>hs=a<em>(x-x0)+b<\/em>(y-y0)+c*(z-z0)<\/p>\n<p>\u53ea\u9700\u5c07\u9ede(x,y,z)\u5e36\u5165\u65b9\u7a0b\u4e2d\u4e26\u8a08\u7b97\u7d50\u679c<\/p>\n<p>\u5982\u679chs=0\u5247\u8a72\u9ede\u4f4d\u65bc\u5e73\u9762\u4e4b\u4e0a<\/p>\n<p>\u5982\u679chs&gt;0\u5247\u8a72\u9ede\u4f4d\u65bc\u5e73\u9762\u6b63\u534a\u7a7a\u9593(\u6cd5\u7dda\u6307\u5411)\u4e2d<\/p>\n<p>\u5982\u679chs&lt;0\u5247\u8a72\u9ede\u4f4d\u65bc\u5e73\u9762\u8ca0\u534a\u7a7a\u9593\u4e2d<\/p>\n<p>float Compute_Point_In_Plane3D(PLANE3D_PTR plane,<a href=\"https:\/\/www.bookcard.net\/wordpress\/game_model_vector3d\/\">VECTOR3D_PTR<\/a> pt){<\/p>\n<p>float hs = plane-&gt;A * pt-&gt;x + plane-&gt;B * pt-&gt;y + plane-&gt;C * pt-&gt;z + plane-&gt;D;<\/p>\n<p>return(hs); \/\/ \u8fd4\u56de\u534a\u7a7a\u9593\u503c<\/p>\n<p>}<\/p>\n<p>&nbsp;<\/p>\n<p>\u8a08\u7b97\u5e73\u9762\u8207\u76f4\u7dda\u4e4b\u76f8\u4ea4\u9ede(3D\u7a7a\u9593)<\/p>\n<p>\u5e73\u9762\u300e\u9802\u9ede\u300f\u8207\u300e\u6cd5\u7dda\u300f\u65b9\u7a0b\u5982\u4e0b:<\/p>\n<p>a<em>(x-x0)+b<\/em>(y-y0)+c*(z-z0)=0<\/p>\n<p>3D\u76f4\u7dda\u65b9\u7a0b\u5982\u4e0b:<\/p>\n<p>(x-x0)\/a = (y-y0)\/b = (z-z0)\/c<\/p>\n<p>\u8a08\u7b97\u591a\u908a\u5f62\u6cd5\u7dda\u8207\u76f4\u7dda\u65b9\u5411\u9ede\u7a4d<\/p>\n<p>double a = plane-&gt;n % (line-&gt;v);<\/p>\n<p>\u82e5\u70ba\u96f6\u5247\u76f4\u7dda\u8207\u5e73\u9762\u5e73\u884c<\/p>\n<p>VECTOR3D Intersect;<\/p>\n<p>if (a == 0)<\/p>\n<p>Intersect = line-&gt;p0;<\/p>\n<p>\u8a08\u7b97\u76f8\u4ea4\u9ede<\/p>\n<p>Intersect = line-&gt;p0 &#8211; (line-&gt;v) * ((plane-&gt;n % line-&gt;p0 + plane-&gt;D) \/ a);<\/p>\n<p>3D\u7dda\u6bb5\u82073D\u5e73\u9762\u4ea4\u9ede\u51fd\u5f0f:<\/p>\n<p>bool Intersect_Line3D_Plane3D(PLANE3D_PTR plane, PARMLINE3D_PTR line,POINT3D_PTR pt){<\/p>\n<p>\/\/ \u8a08\u7b97\u76f4\u7dda\u65b9\u5411\u8207\u591a\u908a\u5f62\u6cd5\u7dda\u9ede\u7a4d<\/p>\n<p>double a = plane-&gt;n % (line-&gt;v);<\/p>\n<p>if (a == 0)<\/p>\n<p>return false;<\/p>\n<p>\/\/ \u8a08\u7b97\u76f8\u4ea4\u9ede<\/p>\n<p>*pt = line-&gt;p0 &#8211; (line-&gt;v) * ((plane-&gt;n % line-&gt;p0 + plane-&gt;D) \/ a);<\/p>\n<p>return true;<\/p>\n<p>}<\/p>\n<p>&nbsp;<\/p>\n<p>\u8a08\u7b97\u9802\u9ede\u662f\u5426\u70ba\u65bc\u591a\u908a\u5f62\u4e4b\u4e0a,<\/p>\n<p>\u9996\u5148\u8a08\u7b97\u9802\u9ede\u8207\u591a\u908a\u5f62\u6240\u6709\u9802\u9ede\u4e4b\u9593\u89d2\u5ea6\u7e3d\u548c.\u5982\u679c\u8a72\u9802\u9ede\u4f4d\u65bc\u591a\u908a\u5f62\u4e4b\u4e0a.\u90a3\u9ebc\u6b64\u9802\u9ede\u8207\u591a\u908a\u5f62\u6240\u6709\u9802\u9ede\u4e4b\u9593\u89d2\u5ea6\u7e3d\u548c\u5c07\u7b49\u65bc\u6216\u63a5\u8fd12PI<\/p>\n<p>bool Intersect_Vector3D_Polygon3D(VECTOR3D_PTR polygon, int num,VECTOR3D_PTR v){<\/p>\n<p>VECTOR3D segment1, segment2;\/\/ \u9802\u9ede \u5230 \u591a\u908a\u5f62\u9802\u9ede \u77e2\u91cf<\/p>\n<p>double length1, length2;\/\/ \u77e2\u91cf\u9577\u5ea6<\/p>\n<p>double sumAngle = 0;\/\/ \u77e2\u91cf\u4e4b\u9593\u89d2\u5ea6\u7e3d\u548c<\/p>\n<p>double cosAngle = 0;\/\/ \u5169\u77e2\u91cf\u4f59\u5f26\u89d2<\/p>\n<p>\/\/ \u7de8\u66c6\u591a\u908a\u5f62\u6240\u6709\u9802\u9ede<\/p>\n<p>for (int index = 0; index &lt; num; ++index)\u00a0\u00a0\u00a0\u00a0 {<\/p>\n<p>segment1 = polygon[index] &#8211; *v;<\/p>\n<p>segment2 = polygon[(index+1) % num] &#8211; *v; \/\/ % num \u78ba\u4fdd\u6578\u503c\u74b0\u5f62\u52a0\u4e00<\/p>\n<p>length1 = Length_VECTOR3D(&amp;segment1);<\/p>\n<p>length2 = Length_VECTOR3D(&amp;segment2);\/\/ \u77e2\u91cf\u9577\u5ea6<\/p>\n<p>\/\/\u6aa2\u67e5\u9802\u9ede\u662f\u5426\u843d\u5728\u591a\u908a\u5f62\u908a\u754c\u4e0a<\/p>\n<p>if ( length1 * length2 &lt;= 0.0000001f){<\/p>\n<p>\/\/ \u591a\u908a\u5f62\u908a\u754c\u88ab\u8a8d\u70ba\u662f\u591a\u908a\u5f62\u5167\u90e8<\/p>\n<p>sumAngle = PI2; \/\/ pai * 2<\/p>\n<p>break;<\/p>\n<p>}<\/p>\n<p>\/\/ \u8a08\u7b97\u4e0a\u8ff0\u5169\u500b\u77e2\u91cf\u4e4b\u9593\u4f59\u5f26\u89d2<\/p>\n<p>cosAngle = (segment1 % segment2) \/ (length1 * length2);<\/p>\n<p>\/\/ \u5c07\u8a08\u7b97\u7d50\u679c\u7d2f\u52a0\u5165\u89d2\u5ea6\u7e3d\u548c<\/p>\n<p>sumAngle = sumAngle + acosf(cosAngle);<\/p>\n<p>}<\/p>\n<p>if ((sumAngle &lt;= PI2 + 0.0000001f) &amp;&amp; (sumAngle &gt;= PI2 &#8211; 0.0000001f))<\/p>\n<p>return true;\/\/ \u9802\u9ede\u8207\u591a\u908a\u5f62\u767c\u751f\u78b0\u649e<\/p>\n<p>else<\/p>\n<p>return false;<\/p>\n<p>return true;<\/p>\n<p>}<\/p>\n<p>&nbsp;<\/p>\n<p>\u4f7f\u7528\u4e09\u500b\u9802\u9ede\u521d\u59cb\u5316(\u5b9a\u7fa9)3D\u5e73\u9762!<\/p>\n<p>void Init_PLANE3D(PLANE3D_PTR plane,VECTOR3D_PTR va,VECTOR3D_PTR vb,VECTOR3D_PTR vc){<\/p>\n<p>VECTOR3D normalA = *vc &#8211; *va;\/\/ \u8a08\u7b97\u9802\u9edeC-&gt;A\u5411\u91cf<\/p>\n<p>VECTOR3D normalB = *vc &#8211; *vb;\/\/ \u8a08\u7b97\u9802\u9edeC-&gt;B\u5411\u91cf<\/p>\n<p>plane-&gt;n = Cross_VECTOR3D(&amp;normalA, &amp;normalB);\/\/ \u8a08\u7b97\u5169\u500b3D\u5411\u91cf\u53c9\u7a4d<\/p>\n<p>plane-&gt;D = Dot_VECTOR3D(&amp;(-(*va)), &amp;plane-&gt;n); \/\/\u8ddd\u96e2\u7b49\u65bcva\u6c42\u8fd4\u5f8c\u8207n\u6c42\u9ede\u7a4d<\/p>\n<p>}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5e73\u9762\u662f3D\u5716\u5f62\u5b78\u91cd\u8981\u90e8\u5206.\u5e73\u9762\u6709\u5169\u500b\u91cd\u8981\u6982\u5ff5. 1.3D\u5e73\u9762\u90fd\u7121\u7aae\u9060\u5ef6\u4f38 2.\u6240\u6709\u5e73\u9762\u90fd\u5c07\u6574\u500b\u7a7a\u9593\u5206\u6210\u5169\u500b\u534a\u7a7a &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.bookcard.net\/wordpress\/game_model_plane\/\" class=\"more-link\">\u7e7c\u7e8c\u95b1\u8b80 <span class=\"screen-reader-text\">\u904a\u6232\u5efa\u6a21-\u5e73\u9762\u78b0\u649e<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11,13],"tags":[42],"class_list":["post-4177","post","type-post","status-publish","format-standard","hentry","category-algorithm","category-pc","tag-computer","entry"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/posts\/4177","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/comments?post=4177"}],"version-history":[{"count":1,"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/posts\/4177\/revisions"}],"predecessor-version":[{"id":4179,"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/posts\/4177\/revisions\/4179"}],"wp:attachment":[{"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/media?parent=4177"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/categories?post=4177"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/tags?post=4177"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}