{"id":1715,"date":"2024-08-20T08:00:00","date_gmt":"2024-08-20T00:00:00","guid":{"rendered":"http:\/\/www.wyrcad.com\/?p=1715"},"modified":"2024-08-23T20:33:37","modified_gmt":"2024-08-23T12:33:37","slug":"autocad-%e5%87%bd%e6%95%b0%e7%b3%bb%e5%88%97%e4%b9%8b%e4%ba%8c","status":"publish","type":"post","link":"https:\/\/www.wyrcad.com\/?p=1715","title":{"rendered":"AutoCAD \u51fd\u6570\u7cfb\u5217\u4e4b\u4e8c"},"content":{"rendered":"\n<p>Private Function GetAngle(ByRef APoint() As Double, ByRef BPoint() As Double) As Double &#8216;X \u2013 Y \u5750\u6807\u7cfb\u5185 \u2460 \u2461 \u4e24\u70b9\u8fde\u7ebf\u7684\u89d2\u5ea6<br>Dim XDiff, YDiff As Double<br>XDiff = BPoint(0) &#8211; APoint(0)<br>YDiff = BPoint(1) &#8211; APoint(1)<br>Dim dTemp As Double<br>&#8216;\u2460\u2013\u2013\u2013\u2013\u2461<br>If XDiff > 0 And YDiff = 0 Then &#8216;X \u8f74\u53f3\u6bb5<br>GetAngle = 0 &#8216;\u5f27\u5ea6<br>End If<br>&#8216;\u2013\u2013\u2013\u2013\u2461<br>&#8216;\u2013\u2013\u2013\/<br>&#8216;\u2013\u2013\/<br>&#8216;\u2013\/<br>&#8216;\u2460<br>If XDiff > 0 And YDiff > 0 Then &#8216;\u7b2c\u4e00\u8c61\u9650<br>dTemp = YDiff \/ XDiff<br>GetAngle = Atn(dTemp) &#8216;\u5f27\u5ea6<br>End If<br>&#8216;\u2461<br>&#8216;|<br>&#8216;|<br>&#8216;|<br>&#8216;\u2460<br>If XDiff = 0 And YDiff > 0 Then &#8216;Y \u8f74\u4e0a\u6bb5<br>GetAngle = 0.5 * PI &#8216;\u5f27\u5ea6<br>End If<br>&#8216;\u2461<br>&#8216;\u2013\\<br>&#8216;\u2013\u2013\\<br>&#8216;\u2013\u2013\u2013\\<br>&#8216;\u2013\u2013\u2013\u2013\u2460<br>If XDiff &lt; 0 And YDiff > 0 Then &#8216;\u7b2c\u4e8c\u8c61\u9650<br>dTemp = Abs(XDiff) \/ YDiff<br>GetAngle = 0.5 * PI + Atn(dTemp) &#8216;\u5f27\u5ea6<br>End If<br>&#8216;\u2461\u2013\u2013\u2013\u2013\u2460<br>If XDiff &lt; 0 And YDiff = 0 Then &#8216;X \u8f74\u5de6\u6bb5 GetAngle = 1 * PI &#8216;\u5f27\u5ea6 End If &#8216;\u2013\u2013\u2013\u2013\u2460 &#8216;\u2013\u2013\u2013\/ &#8216;\u2013\u2013\/ &#8216;\u2013\/ &#8216;\u2461 If XDiff &lt; 0 And YDiff &lt; 0 Then &#8216;\u7b2c\u4e09\u8c61\u9650 dTemp = Abs(YDiff) \/ Abs(XDiff) GetAngle = 1 * PI + Atn(dTemp) &#8216;\u5f27\u5ea6 End If &#8216;\u2460 &#8216;| &#8216;| &#8216;| &#8216;\u2461 If XDiff = 0 And YDiff &lt; 0 Then &#8216;Y \u8f74\u4e0b\u6bb5 GetAngle = 1.5 * PI &#8216;\u5f27\u5ea6 End If &#8216;\u2460 &#8216;\u2013\\ &#8216;\u2013\u2013\\ &#8216;\u2013\u2013\u2013\\ &#8216;\u2013\u2013\u2013\u2013\u2461 If XDiff > 0 And YDiff &lt; 0 Then &#8216;\u7b2c\u56db\u8c61\u9650<br>dTemp = XDiff \/ Abs(YDiff)<br>GetAngle = 1.5 * PI + Atn(dTemp) &#8216;\u5f27\u5ea6<br>End If<br>&#8216;\u2460\u00d7\u2461<br>If XDiff = 0 And YDiff = 0 Then &#8216;\u539f\u70b9<br>GetAngle = 0 &#8216;\u5f27\u5ea6<br>End If<br>End Function<\/p>\n\n\n\n<p>Private Function GetDistance(ByRef APoint() As Double, ByRef BPoint() As Double) As Double &#8216;\u6570\u7ec4\u505a\u53c2\u6570, \u4e24\u70b9\u7684\u77e2\u91cf\u8ddd\u79bb<br>&#8216;\u83b7\u5f97\u4ece APoint \u81f3 BPoint \u7684\u6709\u65b9\u5411\u8ddd\u79bb\uff0c\u4ece\u897f\u5230\u4e1c\u7684\u6247\u5f62\u9762\u79ef\u5185\u4e3a\u6b63\uff08\u8fb9\u754c\u5b9a\u4e49\u5982\u4e0b\uff0c\u6b63\u5317\u5230\u6b63\u5357\u4e3a\u8d1f\uff0c\u6b63\u5357\u5230\u6b63\u5317\u4e3a\u6b63\uff09<br>GetDistance = (BPoint(0) &#8211; APoint(0)) ^ 2 + (BPoint(1) &#8211; APoint(1)) ^ 2 &#8216;\u56fe\u5f62\u5355\u4f4d<br>GetDistance = Sqr(GetDistance) &#8216;\u56fe\u5f62\u5355\u4f4d<br>Dim iSign As Integer<br>If GetAngle(APoint, BPoint) &gt; 0.5 * PI And GetAngle(APoint, BPoint) &lt;= 1.5 * PI Then<br>iSign = -1<br>Else<br>iSign = 1<br>End If<br>GetDistance = iSign * GetDistance<br>End Function<\/p>\n\n\n\n<p>Private Function GetSide(ByRef APoint() As Double, ByRef BPoint() As Double, ByRef CPoint() As Double) As String &#8216;\u6570\u7ec4\u505a\u53c2\u6570<br>&#8216;\u5224\u65ad\u70b9 CPoint \u5728\u4ece\u70b9 APoint \u81f3\u70b9 BPoint \u5f62\u6210\u7684\u6709\u65b9\u5411\u76f4\u7ebf\u7684\u54ea\u4e00\u4fa7<br>Dim Vector01X As Double<br>Dim Vector01Y As Double<br>Vector01X = BPoint(0) &#8211; APoint(0)<br>Vector01Y = BPoint(1) &#8211; APoint(1)<\/p>\n\n\n\n<p>Dim Vector02X As Double<br>Dim Vector02Y As Double<br>Vector02X = CPoint(0) &#8211; APoint(0)<br>Vector02Y = CPoint(1) &#8211; APoint(1)<br>Select Case Vector01X * Vector02Y &#8211; Vector02X * Vector01Y<br>Case 0<br>GetSide = &#8220;ABOVE&#8221;<br>Case Is &gt; 0<br>GetSide = &#8220;LEFT&#8221;<br>Case Is &lt; 0<br>GetSide = &#8220;RIGHT&#8221;<br>End Select<br>End Function<\/p>\n\n\n\n<p>Private Function GetPosition(ByRef APoint() As Double, ByRef BPoint() As Double, ByRef CPoint() As Double) As String &#8216;\u6570\u7ec4\u505a\u53c2\u6570<br>&#8216;\u5224\u65ad\u70b9 CPoint \u5728\u4ece\u70b9 APoint \u81f3\u70b9 BPoint \u5f62\u6210\u7684\u6709\u65b9\u5411\u76f4\u7ebf\u7684\u54ea\u4e00\u6bb5\uff0c\u4e09\u70b9\u4e0d\u5171\u7ebf \u8fd4\u56de -1<br>GetPosition = &#8220;-1&#8221;<br>If Not GetSide(APoint, BPoint, CPoint) = &#8220;ABOVE&#8221; Then Exit Function<br>If GetDistance(APoint, BPoint) &gt;= 0 And GetDistance(APoint, CPoint) &gt;= 0 Then<br>If GetDistance(APoint, BPoint) &gt;= GetDistance(APoint, CPoint) Then<br>GetPosition = &#8220;INSIDE&#8221;<br>Else<br>GetPosition = &#8220;FRONT&#8221;<br>End If<br>End If<br>If GetDistance(APoint, BPoint) &lt; 0 And GetDistance(APoint, CPoint) &lt; 0 Then If GetDistance(APoint, BPoint) &lt; GetDistance(APoint, CPoint) Then GetPosition = &#8220;INSIDE&#8221; Else GetPosition = &#8220;FRONT&#8221; End If End If If GetDistance(APoint, BPoint) &gt;= 0 And GetDistance(APoint, CPoint) &lt; 0 Then GetPosition = &#8220;REAR&#8221; End If If GetDistance(APoint, BPoint) &lt; 0 And GetDistance(APoint, CPoint) &gt;= 0 Then<br>GetPosition = &#8220;REAR&#8221;<br>End If<br>End Function<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Private Function GetAngle(ByRef APoint() As Double, ByR &hellip; <a href=\"https:\/\/www.wyrcad.com\/?p=1715\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u201cAutoCAD \u51fd\u6570\u7cfb\u5217\u4e4b\u4e8c\u201d<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[24,17],"class_list":["post-1715","post","type-post","status-publish","format-standard","hentry","category-bianchengyuandi","tag-vb","tag-biancheng"],"_links":{"self":[{"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=\/wp\/v2\/posts\/1715","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1715"}],"version-history":[{"count":3,"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=\/wp\/v2\/posts\/1715\/revisions"}],"predecessor-version":[{"id":1732,"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=\/wp\/v2\/posts\/1715\/revisions\/1732"}],"wp:attachment":[{"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1715"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1715"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1715"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}