| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 641 人关注过本帖
标题:vfp 会将1.58 与1.60当作同一个数处理吗?
取消只看楼主 加入收藏
FUNFUNHO
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2012-6-5
结帖率:0
收藏
已结贴  问题点数:20 回复次数:2 
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



2012-06-10 00:50
FUNFUNHO
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2012-6-5
收藏
得分:0 
回复 4楼 sdta
好方法!
试过之后结果是false!
那到底是什么原因使得当两点的横坐标很相近的时候 无法画出直线呢?
2012-06-10 10:24
FUNFUNHO
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2012-6-5
收藏
得分:0 
回复 7楼 茵梦湖
强悍!!!
我试了您提供的代码~~~ 高效啊~~~
但是我没大看明白代码的含义...
crea curs tmp (x n(7,2), y n(7,2)) && 我通过vfp里的帮助查找 "crea""curs"的含义 但是它显示无法找到该主题
for kk=1 to 3                      && 这一部分是循环
    inse into tmp valu(int(rand()*200)/60,int(rand()*200)/60)
endfor
sele * from tmp orde by x,y into curs tmp  && 按排出的顺序放入数组中?
sele subs("ABC",recn(),1) 点,* from tmp into curs tmp && 对弹出的表单的第一列的设计
brow titl " 此为任意3点的坐标并排序~"    && 对弹出的表单的表头的设计

最后需要将这排序好的三个点的横纵坐标分别赋予变量Ax Ay Bx B Cx Cy
该如何调用数组(?)中的数达到效果呢?

我上面po的代码是我整个设计的代码
我想要实现的功能是:
三个村庄(随机的三点)合建水库(建在x轴上)
求解最佳(距离最短)铺设路径
2012-06-10 16:23
快速回复:vfp 会将1.58 与1.60当作同一个数处理吗?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.020934 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved