nxy_918 发表于 2006-5-20 13:38:00

一个数学问题?

本帖最后由 作者 于 2006-5-22 19:11:32 编辑 <br /><br /> <P>已知矢量 A(x1,y1),B(x2,y2),C(x3,y3),D(x4,y4)</P>
<P>那么得到矢量A-B=(x1-x2,y1-y2), C-D=(x3-x4,y3-y4)</P>
<P>那么(A-B)*(C-D)是不是等于</P>
<P>(x1-x2,y1-y2)*(x3-x4,y3-y4) </P>
<P>=(x1-x2)*(y3-y4)-(x3-x4)*(y1-y2)</P>
<P>?</P>
<P>还有就是如果A、B、C、D为四个点,那么有向线段AB是不是可以表达成矢量A-B,即(x1-x2,y1-y2), 同理有向线段CD为C-D=(x3-x4,y3-y4)</P>
<P>这样操作对吗?</P>

fjfhgdwfn 发表于 2006-5-22 16:25:00

<P>还不如把你想干什么写出来好呢!“*”与“×”是有区别的啊</P>

nxy_918 发表于 2006-5-22 19:10:00

<P>我根据<A href="http://bbs.mjtd.com/forum.php?mod=viewthread&tid=48974" target="_blank" >http://bbs.mjtd.com/forum.php?mod=viewthread&tid=48974</A>这里的线段相交判断方法,写的判断程序好像有点错误,大家帮我看看</P>
<P>Function L2L_Intersect(A() As Double, B() As Double, C() As Double, D() As Double) As Boolean<BR>Dim Xmax_1, Xmax_2, Xmin_1, Xmin_2, Ymax_1, Ymax_2, Ymin_1, Ymin_2 As Double<BR>Dim V1&nbsp; As Double, V2 As Double<BR>Dim V3&nbsp; As Double, V4 As Double<BR>If A(0) &gt; B(0) Then<BR>&nbsp;&nbsp; Xmax_1 = A(0)<BR>&nbsp;&nbsp; Xmin_1 = B(0)<BR>Else<BR>&nbsp;&nbsp; Xmax_1 = B(0)<BR>&nbsp;&nbsp; Xmin_1 = A(0)<BR>End If<BR>If A(1) &gt; B(1) Then<BR>&nbsp;&nbsp; Ymax_1 = A(1)<BR>&nbsp;&nbsp; Ymin_1 = B(1)<BR>Else<BR>&nbsp;&nbsp; Ymax_1 = B(1)<BR>&nbsp;&nbsp; Ymin_1 = A(1)<BR>End If</P>
<P>If C(0) &gt; D(0) Then<BR>&nbsp;&nbsp; Xmax_2 = C(0)<BR>&nbsp;&nbsp; Xmin_2 = D(0)<BR>Else<BR>&nbsp;&nbsp; Xmax_2 = D(0)<BR>&nbsp;&nbsp; Xmin_2 = C(0)<BR>End If<BR>If C(1) &gt; D(1) Then<BR>&nbsp;&nbsp; Ymax_2 = C(1)<BR>&nbsp;&nbsp; Ymin_2 = D(1)<BR>Else<BR>&nbsp;&nbsp; Ymax_2 = D(1)<BR>&nbsp;&nbsp; Ymin_2 = C(1)<BR>End If<BR>L2L_Intersect = False<BR>If Xmax_1 &lt; Xmin_2 Or Xmin_1 &gt; Xmax_2 Or Ymin_1 &gt; Ymax_2 Or Ymax_1 &lt; Ymin_2 Then&nbsp;&nbsp; '两线段最小矩形不相交,得出两线段不相交<BR>&nbsp;&nbsp; L2L_Intersect = False<BR>&nbsp;&nbsp; Exit Function<BR>Else&nbsp;&nbsp; '利用向量的叉积性质,当其中一条线段的两个端点在另一条线段的同一侧时,不相交。否则,相交。<BR>&nbsp;&nbsp; V1 = (C(0) - A(0)) * (B(1) - A(1)) - (B(0) - A(0)) * (C(1) - A(1))<BR>&nbsp;&nbsp; V2 = (B(0) - A(0)) * (D(1) - A(1)) - (D(0) - A(0)) * (B(1) - A(1))<BR>&nbsp;&nbsp; V3 = (A(0) - C(0)) * (D(1) - C(1)) - (D(0) - C(0)) * (A(1) - C(1))<BR>&nbsp;&nbsp; V4 = (D(0) - C(0)) * (D(1) - C(1)) - (B(0) - C(0)) * (D(1) - C(1))<BR>&nbsp;&nbsp; If V1 * V2 &gt;= 0 And V3 * V4 &gt;= 0 Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; L2L_Intersect = True<BR>&nbsp;&nbsp; End If<BR>End If<BR>End Function</P>
<P>这个程序对有些图形判断正确有些有错误,我上传的图中两线段就判断出错,不知道为什么,大家帮我看看,</P>

nxy_918 发表于 2006-5-25 15:54:00

<P>没人肯帮忙!!!</P>
页: [1]
查看完整版本: 一个数学问题?