{"id":4376,"date":"2018-08-02T09:36:18","date_gmt":"2018-08-02T01:36:18","guid":{"rendered":"http:\/\/www.bookcard.net\/wordpress\/?p=4376"},"modified":"2018-08-02T09:36:18","modified_gmt":"2018-08-02T01:36:18","slug":"android_game_rect_2d_overlap","status":"publish","type":"post","link":"https:\/\/www.bookcard.net\/wordpress\/android_game_rect_2d_overlap\/","title":{"rendered":"Android\u904a\u6232\u4e4b\u300e\u8ef8\u5c0d\u9f4a\u908a\u754c\u76d2\u300f\u78b0\u649e"},"content":{"rendered":"<figure id=\"attachment_4377\" aria-describedby=\"caption-attachment-4377\" style=\"width: 1200px\" class=\"wp-caption alignnone\"><a href=\"https:\/\/www.bookcard.net\/wordpress\/wp-content\/uploads\/2018\/08\/Android_Game_Rect_2D_Overlap.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-4377\" src=\"https:\/\/www.bookcard.net\/wordpress\/wp-content\/uploads\/2018\/08\/Android_Game_Rect_2D_Overlap.jpg\" alt=\"\" width=\"1200\" height=\"800\" srcset=\"https:\/\/www.bookcard.net\/wordpress\/wp-content\/uploads\/2018\/08\/Android_Game_Rect_2D_Overlap.jpg 1200w, https:\/\/www.bookcard.net\/wordpress\/wp-content\/uploads\/2018\/08\/Android_Game_Rect_2D_Overlap-300x200.jpg 300w, https:\/\/www.bookcard.net\/wordpress\/wp-content\/uploads\/2018\/08\/Android_Game_Rect_2D_Overlap-768x512.jpg 768w, https:\/\/www.bookcard.net\/wordpress\/wp-content\/uploads\/2018\/08\/Android_Game_Rect_2D_Overlap-1024x683.jpg 1024w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/><\/a><figcaption id=\"caption-attachment-4377\" class=\"wp-caption-text\">Android\u904a\u6232\u4e4b\u300e\u8ef8\u5c0d\u9f4a\u908a\u754c\u76d2\u300f\u78b0\u649e<\/figcaption><\/figure>\n<p>\u5927\u90e8\u5206\u6a21\u5f62\u90fd\u9069\u5408\u4f7f\u7528\u300e<a href=\"https:\/\/www.bookcard.net\/wordpress\/android_game_circle_2d_overlap\/\">\u5713\u5f62\u78b0\u649e<\/a>\u300f.\u4f46\u82e5\u6a21\u5f62\u5448\u9577\u689d\u5f62\u5247\u9069\u5408\u4f7f\u7528\u300e\u77e9\u5f62\u78b0\u649e\u300f.\u4e5f\u7a31\u70ba\u300e\u8ef8\u5c0d\u9f4a\u908a\u754c\u76d2\u78b0\u649e\u300f.\u7279\u9ede\u662f\u9802\u5e95\u908a\u8207X\u8ef8\u5e73\u884c,\u5de6\u53f3\u908a\u8207Y\u8ef8\u5e73\u884c.\u78b0\u649e\u7b97\u6cd5\u4ee5\u5305\u570d\u8457\u5c0d\u8c61\u6700\u5c0f\u77e9\u5f62.\u4f46\u7f3a\u9ede\u662f\u7121\u6cd5\u96a8\u7269\u9ad4\u65cb\u8f49.\u901f\u5ea6\u5feb\u4f46\u7cbe\u5ea6\u8f03\u5dee.\u82e5\u5b9a\u7fa9\u77e9\u5f62\u5247\u7531\u4e2d\u5fc3\u4f4d\u7f6e\u8207\u9577\u5bec\u6240\u7d44\u6210.<\/p>\n<p>public class RECT2D {<\/p>\n<p>\u77e9\u5f62\u4e2d\u5fc3\u4f4d\u7f6e<\/p>\n<p>public <a href=\"https:\/\/www.bookcard.net\/wordpress\/android_game_2d_vector\/\">VECTOR2D<\/a> center;<\/p>\n<p>\u77e9\u5f62\u5bec\u8207\u9ad8<\/p>\n<p>public float\u00a0 width;<\/p>\n<p>public float\u00a0 height;<\/p>\n<p>\u8cfc\u9020\u300e\u8ef8\u5c0d\u9f4a\u908a\u754c\u76d2\u300f\u8f38\u5165\u4e2d\u5fc3\u4f4d\u7f6e\u8207\u5bec\u9ad8.<\/p>\n<p>public RECT2D(float x,float y,float width,float height){<\/p>\n<p>this.center = new <a href=\"https:\/\/www.bookcard.net\/wordpress\/android_game_2d_vector\/\">VECTOR2D(x, y)<\/a>;\u00a0\u00a0\u00a0 \/\/ \u4e2d\u5fc3\u9ede<\/p>\n<p>this.width\u00a0 = width;<\/p>\n<p>this.height = height;<\/p>\n<p>}<\/p>\n<p>\u300e\u9ede\u300f\u8207\u300e\u77e9\u5f62\u300f\u78b0\u649e.\u82e5\u9ede\u70ba\u65bc\u56db\u689d\u908a\u4e4b\u5167\u5247\u767c\u751f\u78b0\u649e<\/p>\n<p>public boolean overlap(VECTOR2D point){<\/p>\n<p>if(point.x\u00a0 &lt; center.x + width\/2 &amp;&amp;<\/p>\n<p>point.x\u00a0 &gt; center.x &#8211; width\/2 &amp;&amp;<\/p>\n<p>point.y\u00a0 &lt; center.y + height\/2 &amp;&amp;<\/p>\n<p>point.y\u00a0 &gt; center.y &#8211; height\/2 )<\/p>\n<p>return true;<\/p>\n<p>else<\/p>\n<p>return false;<\/p>\n<p>}<\/p>\n<p>\u5169\u77e9\u5f62\u78b0\u649e\u6e2c\u8a66,\u539f\u9ede\u5728\u5de6\u4e0b\u89d2.\u7b97\u6cd5\u7747\u4e0a\u5716\u6709D\u8907\u96dc.\u300e\u77e9\u5f621\u5de6\u908a\u300f\u5728\u300e\u77e9\u5f622\u53f3\u908a\u300f\u4e4b\u5de6\u5247.\u300e\u77e9\u5f621\u53f3\u908a\u300f\u5728\u300e\u77e9\u5f622\u5de6\u908a\u300f\u4e4b\u53f3\u5247.\u300e\u77e9\u5f621\u5e95\u908a\u300f\u5728\u300e\u77e9\u5f622\u9802\u908a\u300f\u4e4b\u4e0b\u5247.\u300e\u77e9\u5f621\u9802\u908a\u300f\u5728\u300e\u77e9\u5f622\u5e95\u908a\u300f\u4e4b\u4e0a\u5247.\u53ea\u8981\u5168\u90e8\u7b26\u5408\u5247\u5169\u77e9\u5f62\u91cd\u758a.<\/p>\n<p>public boolean overlap(RECT2D rect){<\/p>\n<p>if(center.x &#8211; width\/2 &lt; rect.center.x + rect.width\/2 &amp;&amp;<\/p>\n<p>center.x + width\/2 &gt; rect.center.x &#8211; rect.width\/2 &amp;&amp;<\/p>\n<p>center.y &#8211; height\/2 &lt; rect.center.y + rect.height\/2 &amp;&amp;<\/p>\n<p>center.y + height\/2 &gt; rect.center.y &#8211; rect.height\/2 )<\/p>\n<p>return true;<\/p>\n<p>else<\/p>\n<p>return false;<\/p>\n<p>}<\/p>\n<p>\u300e\u5713\u5f62\u300f\u8207\u300e\u77e9\u5f62\u300f\u78b0\u649e.\u539f\u9ede\u5728\u5de6\u4e0b\u89d2.\u9700\u5148\u8a08\u7b97\u300e\u77e9\u5f62\u300f\u8207\u300e\u5713\u5fc3\u300f\u4e4b\u300e\u6700\u8fd1\u9ede\u300f.\u300e\u5713\u5fc3\u300f\u5728\u300e\u77e9\u5f62\u300f\u4e4b\u5916.\u5247\u300e\u6700\u8fd1\u9ede\u300f\u843d\u5728\u300e\u77e9\u5f62\u300f\u908a\u7de3\u4e4b\u4e0a.\u5982\u679c\u300e\u5713\u5fc3\u300f\u5728\u300e\u77e9\u5f62\u300f\u4e4b\u5167.\u5247\u300e\u6700\u8fd1\u9ede\u300f\u662f\u300e\u5713\u5fc3\u300f.\u7136\u5f8c\u8a08\u7b97\u300e\u5713\u5fc3\u300f\u8207\u300e\u6700\u8fd1\u9ede\u300f\u4e4b\u8ddd\u96e2.\u82e5\u5c0f\u65bc\u300e\u5713\u534a\u5f91\u300f\u5167\u5247\u767c\u751f\u91cd\u758a.<\/p>\n<p>public boolean overlap(<a href=\"https:\/\/www.bookcard.net\/wordpress\/android_game_circle_2d_overlap\/\">CIRCLE2D<\/a> circle){<\/p>\n<p>float closestX = circle.center.x; \/\/ \u5713\u5fc3\u5ea7\u6a19X<\/p>\n<p>float closestY = circle.center.y;\/\/ \u5713\u5fc3\u5ea7\u6a19Y<\/p>\n<p>if(circle.center.x &lt; center.x &#8211; width\/2)<\/p>\n<p>closestX = center.x &#8211; width\/2;<\/p>\n<p>else<\/p>\n<p>if(circle.center.x &gt; center.x + width\/2)<\/p>\n<p>closestX = center.x + width\/2;<\/p>\n<p>if(circle.center.y &lt; center.y &#8211; height\/2)<\/p>\n<p>closestY = center.y &#8211; height\/2;<\/p>\n<p>else<\/p>\n<p>if(circle.center.y &gt; center.y + height\/2)<\/p>\n<p>closestY = center.y + height\/2;<\/p>\n<p>if(<a href=\"https:\/\/www.bookcard.net\/wordpress\/android_game_2d_vector\/\">circle.center.DistSquared(closestX,closestY) <\/a>&lt; circle.radius * circle.radius)<\/p>\n<p>return true; \/\/ \u300e\u5713\u300f\u5167\u5247\u767c\u751f\u78b0\u649e<\/p>\n<p>else<\/p>\n<p>return false; \/\/ \u7121\u767c\u751f\u78b0\u649e<\/p>\n<p>}<\/p>\n<p>}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5927\u90e8\u5206\u6a21\u5f62\u90fd\u9069\u5408\u4f7f\u7528\u300e\u5713\u5f62\u78b0\u649e\u300f.\u4f46\u82e5\u6a21\u5f62\u5448\u9577\u689d\u5f62\u5247\u9069\u5408\u4f7f\u7528\u300e\u77e9\u5f62\u78b0\u649e\u300f.\u4e5f\u7a31\u70ba\u300e\u8ef8\u5c0d\u9f4a\u908a\u754c\u76d2\u78b0\u649e\u300f.\u7279\u9ede\u662f\u9802 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.bookcard.net\/wordpress\/android_game_rect_2d_overlap\/\" class=\"more-link\">\u7e7c\u7e8c\u95b1\u8b80 <span class=\"screen-reader-text\">Android\u904a\u6232\u4e4b\u300e\u8ef8\u5c0d\u9f4a\u908a\u754c\u76d2\u300f\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":[4],"tags":[2],"class_list":["post-4376","post","type-post","status-publish","format-standard","hentry","category-android","tag-android","entry"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/posts\/4376","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=4376"}],"version-history":[{"count":1,"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/posts\/4376\/revisions"}],"predecessor-version":[{"id":4378,"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/posts\/4376\/revisions\/4378"}],"wp:attachment":[{"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/media?parent=4376"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/categories?post=4376"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/tags?post=4376"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}