armylee 发表于 2005-3-30 20:03:00

怎样判断一个点在一条直线上(vba)

rt

fanqinwei 发表于 2005-6-11 14:27:00

垂距为零

mikewolf2k 发表于 2005-6-11 17:13:00

判断该直线与直线某端点的斜率与直线斜率是否相等。

torcky 发表于 2005-8-15 20:06:00

<P>&nbsp;该点到直线两端点的距离和等于直线的长度</P>

matrix 发表于 2006-4-23 14:52:00

<P>可以用VBA实现:</P>
<P>得到起点:line.startpoint</P>
<P>得到端点:line.endpoint</P>
<P>然后再照三楼的方法,三个点确定两个斜率,相等就在直线上,否则,就返回false值</P>

zxj_76 发表于 2006-4-28 16:57:00

<P>三楼的方法可以判断点是否在线段或线段的延长线上;</P>
<P>四楼的方法可以判断点是否在线段上。</P>
<P>如果三楼的判断成立而四楼的判断不成立则点在线段的延长线上。</P>

chffsmc 发表于 2007-4-22 14:02:00

<p>四楼ok</p><p></p>

dengqiaqia 发表于 2007-6-10 00:57:00

计算误差很烦人,老是要判断

jkbanana 发表于 2007-6-17 12:11:00

本帖最后由 作者 于 2007-6-17 13:41:10 编辑 <br /><br /> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;">设直线的两端点分别<b style="mso-bidi-font-weight: normal;">A</b>和<b style="mso-bidi-font-weight: normal;">B</b>, 判断任意点<b style="mso-bidi-font-weight: normal;">P</b>在直线<b style="mso-bidi-font-weight: normal;">AB</b>上否?<p></p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;">解:</p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><span style="mso-spacerun: yes;"><font face="Times New Roman">&nbsp;&nbsp;&nbsp; </font></span>以直线的一端点<b style="mso-bidi-font-weight: normal;"><font face="Times New Roman">A</font></b>为起点<font face="Times New Roman">, </font>另一端点<font face="Times New Roman"><b style="mso-bidi-font-weight: normal;">B</b>&nbsp;</font>和任意点<font face="Times New Roman"><b style="mso-bidi-font-weight: normal;">P</b></font>为终点的矢量分别设为<font face="Times New Roman"><b style="mso-bidi-font-weight: normal;">V</b><sub>0</sub></font>和<font face="Times New Roman"><b style="mso-bidi-font-weight: normal;">V</b><sub>1</sub>. </font>任意点<font face="Times New Roman"><b style="mso-bidi-font-weight: normal;">P</b><br/>&nbsp;&nbsp;&nbsp;</font>点和在直线<b style="mso-bidi-font-weight: normal;">AB</b>上的话,外积<font face="Times New Roman">(<b style="mso-bidi-font-weight: normal;"><span style="COLOR: red;">V</b><sub>0</sub></font></span>×<font face="Times New Roman"><b style="mso-bidi-font-weight: normal;">V</b><sub>1</sub>)</font>的大小为<font face="Times New Roman">0.<p></p></font></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;">即:<b style="mso-bidi-font-weight: normal;"><p></p></b></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><b style="mso-bidi-font-weight: normal;">  <font face="Times New Roman">||</font></b><font face="Times New Roman"><b style="mso-bidi-font-weight: normal;">V</b><sub>0</sub></font>×<font face="Times New Roman"><b style="mso-bidi-font-weight: normal;">V</b><sub>1</sub>||&nbsp;</font>=<font face="Times New Roman">0</font> <font face="Times New Roman">---</font> 任意点<font face="Times New Roman"><b style="mso-bidi-font-weight: normal;">P</b>&nbsp;</font>在直线<b style="mso-bidi-font-weight: normal;">AB</b>上<p></p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; </span><font face="Times New Roman"><b style="mso-bidi-font-weight: normal;">||</b><b style="mso-bidi-font-weight: normal;">V</b><sub>0</sub></font>×<font face="Times New Roman"><b style="mso-bidi-font-weight: normal;">V</b><sub>1</sub>||&nbsp;&lt;&gt;0</font> <font face="Times New Roman">---</font> 任意点<font face="Times New Roman"><b style="mso-bidi-font-weight: normal;">P</b></font>不在直线<b style="mso-bidi-font-weight: normal;">AB</b>上<p></p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;">式中:<font face="Times New Roman"><br/>&nbsp;&nbsp;&nbsp;</font>×为矢量的外积运算符<font face="Times New Roman">.</font></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><font face="Times New Roman">************************************************</font></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;">具体计算如下:</p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;">设直线的端点坐标为<font face="Times New Roman"><br/>&nbsp;&nbsp;&nbsp;<b style="mso-bidi-font-weight: normal;">A </b>= (A(0), A(1), A(2) )<sup>T</sup>, <b style="mso-bidi-font-weight: normal;">B </b>= (B(0), B(1), B(2) )<sup>T</sup>, </font>任意点<font face="Times New Roman"><b style="mso-bidi-font-weight: normal;">P </b>= (P(0), P(1), P(2) )<sup>T</sup><p></p></font></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;">则<font face="Times New Roman">, </font>矢量</p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><font face="Times New Roman"><span style="mso-spacerun: yes;">&nbsp;&nbsp; &nbsp;&nbsp;</span><b style="mso-bidi-font-weight: normal;">V</b><sub>0</sub></font>=<font face="Times New Roman"><b style="mso-bidi-font-weight: normal;">B </b>– <b style="mso-bidi-font-weight: normal;">A</b>, <b style="mso-bidi-font-weight: normal;">V</b><sub>0</sub></font>的成分为:<font face="Times New Roman">V<sub>0</sub>(i)<b style="mso-bidi-font-weight: normal;">&nbsp;</b>= B(i) – A(i ), i=0,2<p></p></font></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><font face="Times New Roman"><span style="mso-spacerun: yes;">&nbsp;&nbsp; &nbsp;&nbsp;</span><b style="mso-bidi-font-weight: normal;">V</b><sub>1</sub></font>=<font face="Times New Roman"><b style="mso-bidi-font-weight: normal;">P </b>– <b style="mso-bidi-font-weight: normal;">A</b>, <b style="mso-bidi-font-weight: normal;">V</b><sub>1</sub></font>的成分为:<font face="Times New Roman"><span style="mso-spacerun: yes;">&nbsp;V</span><sub>1</sub>(i)<b style="mso-bidi-font-weight: normal;">&nbsp;</b>= P(i) – A(i ), i=0,2</font></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;">又设矢量的<span style="COLOR: fuchsia;">外积</span><font face="Times New Roman"><b style="mso-bidi-font-weight: normal;">V</b> = <b style="mso-bidi-font-weight: normal;">V</b><sub>0</sub></font>×<font face="Times New Roman"><b style="mso-bidi-font-weight: normal;">V</b><sub>1</sub>, <b style="mso-bidi-font-weight: normal;">V</b></font>还是矢量<font face="Times New Roman">.</font></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><font face="Times New Roman"><span style="mso-spacerun: yes;">&nbsp;&nbsp; &nbsp;&nbsp;<b style="mso-bidi-font-weight: normal;">V</b> = </span><b style="mso-bidi-font-weight: normal;">V</b><sub>0</sub></font>×<font face="Times New Roman"><b style="mso-bidi-font-weight: normal;">V</b><sub>1</sub><b style="mso-bidi-font-weight: normal;"><p></p></b></font></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><font face="Times New Roman"><span style="mso-spacerun: yes;">&nbsp; &nbsp;&nbsp;&nbsp;<b style="mso-bidi-font-weight: normal;">V</b></font></span>的成分如下<font face="Times New Roman">,</font></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><font face="Times New Roman"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;V</span>(0)= V<sub>0</sub> (1) V<sub>1</sub> (2) – <span style="mso-spacerun: yes;">&nbsp;V</span><sub>0</sub> (2) V<sub>1</sub> (1)</font></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><font face="Times New Roman"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;V</span>(1)= V<sub>0</sub> (2) V<sub>1</sub> (0) – <span style="mso-spacerun: yes;">&nbsp;V</span><sub>0</sub> (0) V<sub>1</sub> (2)</font></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><font face="Times New Roman"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;V</span>(2)= V<sub>0</sub> (0) V<sub>1</sub> (1) – <span style="mso-spacerun: yes;">&nbsp;V</span><sub>0</sub> (1) V<sub>1</sub> (0)</font></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;">则<font face="Times New Roman">, <b style="mso-bidi-font-weight: normal;">||</b><b style="mso-bidi-font-weight: normal;">V</b><sub>0</sub></font>×<font face="Times New Roman"><b style="mso-bidi-font-weight: normal;">V</b><sub>1</sub><b style="mso-bidi-font-weight: normal;">||= </b>sqr(V(0)^2+ V(1)^2+ V(2)^2)</font></p><font face="Times New Roman"><p class="MsoNormal" align="left" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan;"><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: &quot;Times New Roman&quot;; mso-hansi-font-family: &quot;Times New Roman&quot;; mso-bidi-font-size: 10.5pt;">然后用上面的结论即可判断出点<b style="mso-bidi-font-weight: normal;">P</b>在直线<b style="mso-bidi-font-weight: normal;">AB</b>上否<span lang="EN-US" style="mso-bidi-font-size: 10.5pt;"><font face="Times New Roman">.</font></span></p><p class="MsoNormal" align="left" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan;"><span lang="EN-US" style="mso-bidi-font-size: 10.5pt;">以上计算中只要进行简单的<span style="COLOR: fuchsia;">加</span>,减,乘,乘方,开方运算即可.</span></p><span lang="EN-US" style="FONT-SIZE: 10.5pt; FONT-FAMILY: &quot;Times New Roman&quot;; mso-fareast-language: ZH-CN; mso-fareast-font-family: 宋体; mso-bidi-language: AR-SA; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US;"><p class="MsoNormal" align="left" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan;"><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: &quot;Times New Roman&quot;; mso-hansi-font-family: &quot;Times New Roman&quot;; mso-bidi-font-size: 10.5pt;">该方法不论是在2维空间还是3维空间,也不论点在线段AB上,还是在其延长线上,都能使用.<p></p></p></span></span><p></p><p></p><p></p><p></p><p></p><p></p><p></p></span></font>

jkbanana 发表于 2007-6-17 13:25:00

''''''''''''''''''''''''''''''''''''''''''''''<br/>''''''''''''''''''''''''''''''''''''''''''''''<br/>'''<br/>'''这是一个判断点在直线上否的简单Sample<br/>'''<br/>'''Coded By ChunYue,Zou&nbsp;&nbsp; 2007.06.17<br/>''''''''''''''''''''''''''''''''''''''''''''''<br/>''''''''''''''''''''''''''''''''''''''''''''''<br/>Option Explicit<br/>Const CONST_AbsZero = 10 ^ (-4)&nbsp;&nbsp; '大小由计算精度确定<br/>Public Sub Test()<br/>&nbsp; Dim objline As AcadLine<br/>&nbsp; Dim returnPnt As Variant<br/>&nbsp; Dim A(0 To 2) As Double<br/>&nbsp; Dim B(0 To 2) As Double<br/>&nbsp; Dim P(0 To 2) As Double<br/>&nbsp; Dim V(0 To 2) As Double<br/>&nbsp; Dim V0(0 To 2) As Double<br/>&nbsp; Dim V1(0 To 2) As Double<br/>&nbsp; Dim Norm As Double<br/>&nbsp; <br/>'''<br/>&nbsp; '1.指定直线AB<br/>&nbsp; ThisDrawing.Utility.GetEntity objline, returnPnt, "Select a line:"<br/>&nbsp; returnPnt = objline.StartPoint<br/>&nbsp; A(0) = returnPnt(0)<br/>&nbsp; A(1) = returnPnt(1)<br/>&nbsp; A(2) = returnPnt(2)<br/>&nbsp; returnPnt = objline.EndPoint<br/>&nbsp; B(0) = returnPnt(0)<br/>&nbsp; B(1) = returnPnt(1)<br/>&nbsp; B(2) = returnPnt(2)<br/>&nbsp; '指定一任意点P<br/>&nbsp; returnPnt = ThisDrawing.Utility.GetPoint(, "Enter a point: ")<br/>&nbsp; P(0) = returnPnt(0)<br/>&nbsp; P(1) = returnPnt(1)<br/>&nbsp; P(2) = returnPnt(2)<br/>&nbsp; '2.计算矢量V0=B-A, V1=P-A<br/>&nbsp; V0(0) = B(0) - A(0)<br/>&nbsp; V0(1) = B(1) - A(1)<br/>&nbsp; V0(2) = B(2) - A(2)<br/>&nbsp; '<br/>&nbsp; V1(0) = P(0) - A(0)<br/>&nbsp; V1(1) = P(1) - A(1)<br/>&nbsp; V1(2) = P(2) - A(2)<br/>&nbsp; '3.求外积 V = V0 x V1<br/>&nbsp; V(0) = V0(1) * V1(2) - V0(2) * V1(1)<br/>&nbsp; V(1) = V0(2) * V1(0) - V0(0) * V1(2)<br/>&nbsp; V(2) = V0(0) * V1(1) - V0(1) * V1(0)<br/>&nbsp; '4.计算V的大小: Norm = ||V|| = ||V0 X V1||<br/>&nbsp; Norm = Sqr(V(0) ^ 2 + V(1) ^ 2 + V(2) ^ 2)<br/>&nbsp; '5.判断<br/>&nbsp; If Norm &lt; CONST_AbsZero Then<br/>&nbsp;&nbsp;&nbsp; '点P在直线AB上<br/>&nbsp;&nbsp;&nbsp; MsgBox "点在直线上, Norm=" &amp; Norm<br/>&nbsp; Else<br/>&nbsp;&nbsp;&nbsp; '点P不在直线AB上<br/>&nbsp;&nbsp;&nbsp; MsgBox "点不在直线上, Norm=" &amp; Norm<br/>&nbsp; End If<br/>End Sub
页: [1] 2
查看完整版本: 怎样判断一个点在一条直线上(vba)