vfp 会将1.58 与1.60当作同一个数处理吗?
终于编出了一个小程序!正常情况下,是可以得出满意的解答的,
但是在调试的过程中发现了有些情况无答,如下图所示
我自己对此分析的结果是,当三点中存在横坐标很相近的情况时,无法得出解答。
我的代码如下,麻烦各位指点~~~~
a=int(RAND()*200)
b=int(RAND()*200)
c=int(RAND()*200)
d=int(RAND()*200)
e=int(RAND()*200)
f=int(RAND()*200)
&& to draw the 3 villages
clear
thisform.Circle(2,a+thisform.container1.left,-b+thisform.container1.top+thisform.container1.Height)
thisform.Circle(2,c+thisform.container1.left,-d+thisform.container1.top+thisform.container1.Height)
thisform.Circle(2,e+thisform.container1.left,-f+thisform.container1.top+thisform.container1.Height)
&& the program below I get the 3 points ordered by x from little to large
a1=a/60
b1=b/60
c1=c/60
d1=d/60
e1=e/60
f1=f/60
&& to find the bigest X and match the point
IF MAX(a1,c1,e1)== a1
Cx=a1
Cy=b1
ENDIF
IF MAX(a1,c1,e1)==c1 AND c1!=a1
Cx=c1
Cy=d1
ENDIF
IF MAX(a1,c1,e1)==e1 AND e1!=a1 AND e1!=c1
Cx=e1
Cy=f1
ENDIF
&& to find the smallest X and match the point
IF Min(a1,c1,e1)== a1
Ax=a1
Ay=b1
ENDIF
IF Min(a1,c1,e1)==c1 AND c1!=a1
Ax=c1
Ay=d1
ENDIF
IF Min(a1,c1,e1)==e1 AND e1!=a1 AND e1!=c1
Ax=e1
Ay=f1
ENDIF
&& to find the middle one
IF a1+c1+e1-Ax-Cx== a1
Bx=a1
B=b1
ENDIF
IF a1+c1+e1-Ax-Cx==c1
Bx=c1
B=d1
ENDIF
IF a1+c1+e1-Ax-Cx==e1
Bx=e1
B=f1
ENDIF
thisform.text1.value=Ax
thisform.text2.value=Ay
thisform.text3.value=Bx
thisform.text4.value=B
thisform.text5.value=Cx
thisform.text6.value=Cy
&& now we can use the method we have been taught in class , but we need to separate the three situations.
PUBLIC XF, YF
AngB= ( (Ax-Bx)*(Cx-Bx)+(Ay-B)*(Cy-B) ) / ( SQRT((Ax-Bx)^2+(Ay-B)^2) * SQRT( (Cx-Bx)^2+(Cy-B)^2) )
AngA= ( (Bx-Ax)*(Cx-Ax)+(B-Ay)*(Cy-Ay) ) / ( SQRT((Bx-Ax)^2+(B-Ay)^2) * SQRT( (Cx-Ax)^2+(Cy-Ay)^2) )
AngC= ( (Bx-Cx)*(Ax-Cx)+(B-Cy)*(Ay-Cy) ) / ( SQRT((Bx-Cx)^2+(B-Cy)^2) * SQRT( (Cx-Ax)^2+(Cy-Ay)^2) )
KAC=(Ay-Cy)/(Ax-Cx)
&& 1st we don't need to add extra point to the picture
&& 120 <= AngB <= 180
IF AngB<=-1/2 AND AngB>=-1 and B<= Ay and B<= Cy
thisform.Line (Bx*60+thisform.container1.left , -B*60+thisform.container1.top+thisform.container1.Height, Cx*60+thisform.container1.left , -Cy*60+thisform.container1.top+thisform.container1.Height)
thisform.Line(Bx*60+thisform.container1.left , -B*60+thisform.container1.top+thisform.container1.Height, Ax*60+thisform.container1.left , -Ay*60+thisform.container1.top+thisform.container1.Height)
thisform.Line (Bx*60+thisform.container1.left , -B*60+thisform.container1.top+thisform.container1.Height, Bx*60+thisform.container1.left , thisform.container1.top+thisform.container1.Height)
&& L=lBA+lBC+lBX
thisform.text11.Value=SQRT((Bx-Ax)^2+(B-Ay)^2 )+SQRT( (Bx-Cx)^2+(B-Cy)^2 )+ B
thisform.text9.Value=Bx
thisform.text10.Value=0
thisform.Circle(4, Bx*60+thisform.container1.left ,thisform.container1.top+thisform.container1.Height)
ENDIF
IF AngB<=-1/2 AND AngB>=-1 and Ay<B and Ay<Cy
thisform.Line (Bx*60+thisform.container1.left , -B*60+thisform.container1.top+thisform.container1.Height, Cx*60+thisform.container1.left , -Cy*60+thisform.container1.top+thisform.container1.Height)
thisform.Line(Bx*60+thisform.container1.left , -B*60+thisform.container1.top+thisform.container1.Height, Ax*60+thisform.container1.left , -Ay*60+thisform.container1.top+thisform.container1.Height)
thisform.Line (Ax*60+thisform.container1.left , -Ay*60+thisform.container1.top+thisform.container1.Height, Ax*60+thisform.container1.left , thisform.container1.top+thisform.container1.Height)
&& L=lBA+lBC+lAX
thisform.text11.Value=SQRT((Bx-Ax)^2+(B-Ay)^2 )+SQRT( (Bx-Cx)^2+(B-Cy)^2 )+ Ay
thisform.text9.Value=Ax
thisform.text10.Value=0
thisform.Circle(4, Ax*60+thisform.container1.left ,thisform.container1.top+thisform.container1.Height)
ENDIF
IF AngB<=-1/2 AND AngB>=-1 and Cy<B and Cy<Ay && BETWEEN(AngB,-1,-1/2) OR BETWEEN(AngA,-1,-1/2) OR BETWEEN(AngC,-1,-1/2)
thisform.Line (Bx*60+thisform.container1.left , -B*60+thisform.container1.top+thisform.container1.Height, Cx*60+thisform.container1.left , -Cy*60+thisform.container1.top+thisform.container1.Height)
thisform.Line(Bx*60+thisform.container1.left , -B*60+thisform.container1.top+thisform.container1.Height, Ax*60+thisform.container1.left , -Ay*60+thisform.container1.top+thisform.container1.Height)
thisform.Line(Cx*60+thisform.container1.left , -Cy*60+thisform.container1.top+thisform.container1.Height, Cx*60+thisform.container1.left , thisform.container1.top+thisform.container1.Height)
&& L=lBA+lBC+lBX
thisform.text11.Value=SQRT((Bx-Ax)^2+(B-Ay)^2 )+SQRT( (Bx-Cx)^2+(B-Cy)^2 )+ Cy
thisform.text9.Value=Cx
thisform.text10.Value=0
thisform.Circle(4, Cx*60+thisform.container1.left ,thisform.container1.top+thisform.container1.Height)
ENDIF
IF AngA<=-1/2 AND AngA>=-1 and Cy<B and Cy<Ay && BETWEEN(AngB,-1,-1/2) OR BETWEEN(AngA,-1,-1/2) OR BETWEEN(AngC,-1,-1/2)
thisform.Line (Ax*60+thisform.container1.left , -Ay*60+thisform.container1.top+thisform.container1.Height, Cx*60+thisform.container1.left , -Cy*60+thisform.container1.top+thisform.container1.Height)
thisform.Line(Bx*60+thisform.container1.left , -B*60+thisform.container1.top+thisform.container1.Height, Ax*60+thisform.container1.left , -Ay*60+thisform.container1.top+thisform.container1.Height)
thisform.Line(Cx*60+thisform.container1.left , -Cy*60+thisform.container1.top+thisform.container1.Height, Cx*60+thisform.container1.left , thisform.container1.top+thisform.container1.Height)
&& L=lBA+lBC+lCX
thisform.text11.Value=SQRT((Bx-Ax)^2+(B-Ay)^2 )+SQRT( (Bx-Cx)^2+(B-Cy)^2 )+ Cy
thisform.text9.Value=Cx
thisform.text10.Value=0
thisform.Circle(4, Cx*60+thisform.container1.left ,thisform.container1.top+thisform.container1.Height)
ENDIF
IF AngC<=-1/2 AND AngC>=-1 and Ay<B and Ay<Cy
thisform.Line (Bx*60+thisform.container1.left , -B*60+thisform.container1.top+thisform.container1.Height, Cx*60+thisform.container1.left , -Cy*60+thisform.container1.top+thisform.container1.Height)
thisform.Line(Cx*60+thisform.container1.left , -Cy*60+thisform.container1.top+thisform.container1.Height, Ax*60+thisform.container1.left , -Ay*60+thisform.container1.top+thisform.container1.Height)
thisform.Line (Ax*60+thisform.container1.left , -Ay*60+thisform.container1.top+thisform.container1.Height, Ax*60+thisform.container1.left , thisform.container1.top+thisform.container1.Height)
&& L=lBA+lBC+lAX
thisform.text11.Value=SQRT((Bx-Ax)^2+(B-Ay)^2 )+SQRT( (Bx-Cx)^2+(B-Cy)^2 )+ Ay
thisform.text9.Value=Ax
thisform.text10.Value=0
thisform.Circle(4, Ax*60+thisform.container1.left ,thisform.container1.top+thisform.container1.Height)
ENDIF
&& 2nd one is B< min(Ay,Cy) the other is By>max(Ay,Cy) let's do it!
*IF between(AngB,-1/2,1) and between(AngA,-1/2,1) and between(AngC,-1/2,1) and B<= KAC*B+(Ay-KAC*Ax)
IF AngB<1 AND AngB>-1/2 AND AngA<1 AND AngA>-1/2 AND AngC<1 AND AngC>-1/2 AND B<= KAC*B+(Ay-KAC*Ax)
XE=(Ax+Bx)/2+SQRT(3)/2*(B-Ay)
YE=(Ay+B)/2-SQRT(3)/2*(Bx-Ax)
XD=(Ax+Cx)/2-SQRT(3)/2*(Cy-Ay)
YD=(Ay+Cy)/2+SQRT(3)/2*(Cx-Ax)
KBD=(YD-B)/(XD-Bx)
KCE=(YE-Cy)/(XE-Cx)
XF=((Bx*KBD-B)-(Cx*KCE-Cy))/(KBD-KCE)
YF=B+KBD*(XF-Bx)
thisform.Circle(4, XF*60+thisform.container1.left , -YF*60+thisform.container1.top+thisform.container1.Height) && draw the F point
thisform.Line(XF*60+thisform.container1.left , -YF*60+thisform.container1.top+thisform.container1.Height, Ax*60+thisform.container1.left , -Ay*60+thisform.container1.top+thisform.container1.Height) && draw line FA
thisform.Line(XF*60+thisform.container1.left , -YF*60+thisform.container1.top+thisform.container1.Height, Bx*60+thisform.container1.left , -B*60+thisform.container1.top+thisform.container1.Height) && draw line FB
thisform.Line(XF*60+thisform.container1.left , -YF*60+thisform.container1.top+thisform.container1.Height, Cx*60+thisform.container1.left , -Cy*60+thisform.container1.top+thisform.container1.Height) && draw line FC
ENDIF
IF between(AngB,-1/2,1) and between(AngA,-1/2,1) and between(AngC,-1/2,1) and B<= Ay and B<Cy
thisform.Line (Bx*60+thisform.container1.left , -B*60+thisform.container1.top+thisform.container1.Height, Bx*60+thisform.container1.left , thisform.container1.top+thisform.container1.Height)
&& L= lFA+lFB+lFC+lBX
thisform.text11.Value= SQRT((Ax-XF)^2+(Ay-YF)^2)+SQRT((Bx-XF)^2+(B-YF)^2)+SQRT((Cx-XF)^2+(Cy-YF)^2) + B
thisform.text9.Value=Bx
thisform.text10.Value=0
thisform.Circle(4, Bx*60+thisform.container1.left ,thisform.container1.top+thisform.container1.Height)
ENDIF
IF between(AngB,-1/2,1) and between(AngA,-1/2,1) and between(AngC,-1/2,1) and Ay<=B and Ay<Cy
thisform.Line (Ax*60+thisform.container1.left , -Ay*60+thisform.container1.top+thisform.container1.Height, Ax*60+thisform.container1.left , thisform.container1.top+thisform.container1.Height)
&& L= lFA+lFB+lFC+lAX
thisform.text11.Value= SQRT((Ax-XF)^2+(Ay-YF)^2)+SQRT((Bx-XF)^2+(B-YF)^2)+SQRT((Cx-XF)^2+(Cy-YF)^2) + Ay
thisform.text9.Value=Ax
thisform.text10.Value=0
thisform.Circle(4, Ax*60+thisform.container1.left , thisform.container1.top+thisform.container1.Height)
ENDIF
IF between(AngB,-1/2,1) and between(AngA,-1/2,1) and between(AngC,-1/2,1) AND Cy<=B and Cy<Ay
thisform.Line(Cx*60+thisform.container1.left , -Cy*60+thisform.container1.top+thisform.container1.Height, Cx*60+thisform.container1.left , thisform.container1.top+thisform.container1.Height)
&& L= lFA+lFB+lFC+lCX
thisform.text11.Value= SQRT((Ax-XF)^2+(Ay-YF)^2)+SQRT((Bx-XF)^2+(B-YF)^2)+SQRT((Cx-XF)^2+(Cy-YF)^2) + Cy
thisform.text9.Value=Cx
thisform.text10.Value=0
thisform.Circle(4, Cx*60+thisform.container1.left ,thisform.container1.top+thisform.container1.Height)
ENDIF
*IF between(AngB,-1/2,1) and between(AngA,-1/2,1) and between(AngC,-1/2,1) and B> KAC*B+(Ay-KAC*Ax)
IF AngB<1 AND AngB>-1/2 AND AngA<1 AND AngA>-1/2 AND AngC<1 AND AngC>-1/2 AND B> KAC*B+(Ay-KAC*Ax)
XE=(Ax+Bx)/2-SQRT(3)/2*(B-Ay)
YE=(Ay+B)/2+SQRT(3)/2*(Bx-Ax)
XD=(Ax+Cx)/2+SQRT(3)/2*(Cy-Ay)
YD=(Ay+Cy)/2-SQRT(3)/2*(Cx-Ax)
KBD=(YD-B)/(XD-Bx)
KCE=(YE-Cy)/(XE-Cx)
XF=((Bx*KBD-B)-(Cx*KCE-Cy))/(KBD-KCE)
YF=B+KBD*(XF-Bx)
thisform.Circle(4, XF*60+thisform.container1.left , -YF*60+thisform.container1.top+thisform.container1.Height) && draw the F point
thisform.Line(XF*60+thisform.container1.left , -YF*60+thisform.container1.top+thisform.container1.Height, Ax*60+thisform.container1.left , -Ay*60+thisform.container1.top+thisform.container1.Height) && draw line FA
thisform.Line(XF*60+thisform.container1.left , -YF*60+thisform.container1.top+thisform.container1.Height, Bx*60+thisform.container1.left , -B*60+thisform.container1.top+thisform.container1.Height) && draw line FB
thisform.Line(XF*60+thisform.container1.left , -YF*60+thisform.container1.top+thisform.container1.Height, Cx*60+thisform.container1.left , -Cy*60+thisform.container1.top+thisform.container1.Height) && draw line FC
ENDIF
IF between(AngB,-1/2,1) and between(AngA,-1/2,1) and between(AngC,-1/2,1) and B<= Ay and B<Cy
thisform.Line (Bx*60+thisform.container1.left , -B*60+thisform.container1.top+thisform.container1.Height, Bx*60+thisform.container1.left , thisform.container1.top+thisform.container1.Height)
&& L= lFA+lFB+lFC+lBX
thisform.text11.Value= SQRT((Ax-XF)^2+(Ay-YF)^2)+SQRT((Bx-XF)^2+(B-YF)^2)+SQRT((Cx-XF)^2+(Cy-YF)^2) + B
thisform.text9.Value=Bx
thisform.text10.Value=0
thisform.Circle(4, Bx*60+thisform.container1.left ,thisform.container1.top+thisform.container1.Height)
ENDIF
IF between(AngB,-1/2,1) and between(AngA,-1/2,1) and between(AngC,-1/2,1) and Ay<=B and Ay<Cy
thisform.Line (Ax*60+thisform.container1.left , -Ay*60+thisform.container1.top+thisform.container1.Height, Ax*60+thisform.container1.left , thisform.container1.top+thisform.container1.Height)
&& L= lFA+lFB+lFC+lAX
thisform.text11.Value= SQRT((Ax-XF)^2+(Ay-YF)^2)+SQRT((Bx-XF)^2+(B-YF)^2)+SQRT((Cx-XF)^2+(Cy-YF)^2) + Ay
thisform.text9.Value=Ax
thisform.text10.Value=0
thisform.Circle(4, Ax*60+thisform.container1.left ,thisform.container1.top+thisform.container1.Height)
ENDIF
IF between(AngB,-1/2,1) and between(AngA,-1/2,1) and between(AngC,-1/2,1) and Cy<=B and Cy<Ay
thisform.Line(Cx*60+thisform.container1.left , -Cy*60+thisform.container1.top+thisform.container1.Height, Cx*60+thisform.container1.left , thisform.container1.top+thisform.container1.Height)
&& L= lFA+lFB+lFC+lCX
thisform.text11.Value= SQRT((Ax-XF)^2+(Ay-YF)^2)+SQRT((Bx-XF)^2+(B-YF)^2)+SQRT((Cx-XF)^2+(Cy-YF)^2) + Cy
thisform.text9.Value=Cx
thisform.text10.Value=0
thisform.Circle(4, Cx*60+thisform.container1.left ,thisform.container1.top+thisform.container1.Height)
ENDIF
thisform.DrawMode= 13
thisform.drawwidth=1.2