一个数学问题?
本帖最后由 作者 于 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> <P>还不如把你想干什么写出来好呢!“*”与“×”是有区别的啊</P> <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 As Double, V2 As Double<BR>Dim V3 As Double, V4 As Double<BR>If A(0) > B(0) Then<BR> Xmax_1 = A(0)<BR> Xmin_1 = B(0)<BR>Else<BR> Xmax_1 = B(0)<BR> Xmin_1 = A(0)<BR>End If<BR>If A(1) > B(1) Then<BR> Ymax_1 = A(1)<BR> Ymin_1 = B(1)<BR>Else<BR> Ymax_1 = B(1)<BR> Ymin_1 = A(1)<BR>End If</P>
<P>If C(0) > D(0) Then<BR> Xmax_2 = C(0)<BR> Xmin_2 = D(0)<BR>Else<BR> Xmax_2 = D(0)<BR> Xmin_2 = C(0)<BR>End If<BR>If C(1) > D(1) Then<BR> Ymax_2 = C(1)<BR> Ymin_2 = D(1)<BR>Else<BR> Ymax_2 = D(1)<BR> Ymin_2 = C(1)<BR>End If<BR>L2L_Intersect = False<BR>If Xmax_1 < Xmin_2 Or Xmin_1 > Xmax_2 Or Ymin_1 > Ymax_2 Or Ymax_1 < Ymin_2 Then '两线段最小矩形不相交,得出两线段不相交<BR> L2L_Intersect = False<BR> Exit Function<BR>Else '利用向量的叉积性质,当其中一条线段的两个端点在另一条线段的同一侧时,不相交。否则,相交。<BR> V1 = (C(0) - A(0)) * (B(1) - A(1)) - (B(0) - A(0)) * (C(1) - A(1))<BR> V2 = (B(0) - A(0)) * (D(1) - A(1)) - (D(0) - A(0)) * (B(1) - A(1))<BR> V3 = (A(0) - C(0)) * (D(1) - C(1)) - (D(0) - C(0)) * (A(1) - C(1))<BR> V4 = (D(0) - C(0)) * (D(1) - C(1)) - (B(0) - C(0)) * (D(1) - C(1))<BR> If V1 * V2 >= 0 And V3 * V4 >= 0 Then<BR> L2L_Intersect = True<BR> End If<BR>End If<BR>End Function</P>
<P>这个程序对有些图形判断正确有些有错误,我上传的图中两线段就判断出错,不知道为什么,大家帮我看看,</P> <P>没人肯帮忙!!!</P>
页:
[1]