内边界上有点吗?

时间:2018-02-12 16:31:44

标签: pascal freepascal

有一种算法,它将一个点减去圆形,外部/内部边界或圆形内的图形。但是我遇到了这样的问题,它没有正确显示有关圆圈内图形内边界点击的信息。例如,如果指定坐标(-14; 0),它将在内部边界上输出一个"点"并且如果例如指定也落在边界上的坐标(0; 3),它将简单地输出"点进入区域"。我无法理解我犯了什么错误,请告诉我如何修复它?

if (x[i]*x[i]+y[i]*y[i]<=r*r) and (x[i]>=0) or
   (x[i]*x[i]+y[i]*y[i]<=r*r) and (x[i]<=-14)or
   (x[i]*x[i]+y[i]*y[i]<=r*r) and (x[i]<=0) and (y[i]<=round(-b/2)) or
   (x[i]*x[i]+y[i]*y[i]<=r*r) and (x[i]<=0) and (y[i]>=round(b/2))
then t:=t+1;
if (x[i]*x[i]+y[i]*y[i]>r*r) then begin 
   TextOut(65, f, ' - point outside the region');
   f:=f+16;
end
   else if (x[i]*x[i]+y[i]*y[i]=r*r) then begin 
      TextOut(65, f, ' - point on the outer boundary');
      f:=f+16; 
   end
   else if (x[i]*x[i]+y[i]*y[i]<=r*r) and (x[i]>=0) or
           (x[i]*x[i]+y[i]*y[i]<=r*r) and (x[i]<-14) or
           (x[i]*x[i]+y[i]*y[i]<=r*r) and (x[i]<=0) and (y[i]<round(-b/2)) or
           (x[i]*x[i]+y[i]*y[i]<=r*r) and (x[i]<=0) and (y[i]>round(b/2))
           then begin 
              TextOut(65, f, '- the point is the area');
              f:=f+16;
           end
          else if ((x[i]=0) and (y[i]<15) and (y[i]=15)) or
                  ((x[i]=-14) and (y[i]<15) and (y[i]>-15)) or
                  ((y[i]=15) and (x[i]<0) and (x[i]>-14)) or
                  ((y[i]=-15) and (x[i]<0) and (x[i]>-14))
           then begin 
                TextOut(65, f, ' - internal point');
                f:=f+16;
                end
           else begin
                TextOut(65, f, ' - dot in the inner figure');
                f:=f+16;
                end
 end; 

2 个答案:

答案 0 :(得分:1)

您没有显示绘制矩形的代码,但我猜您使用的是普通的GDI函数。根据{{​​3}}函数,矩形不包括其右侧和底侧。

例如,Rect(-14, 15, 0, -15)不包含X=0像素,也不包括y=-15像素。

请参阅Raymond Chen撰写的MS Rectangle有关原因和后果的信息。

答案 1 :(得分:0)

我相信此部分正在尝试识别矩形边框上的点:

      else if ((x[i]=0) and (y[i]<15) and (y[i]=15)) or
              ((x[i]=-14) and (y[i]<15) and (y[i]>-15)) or
              ((y[i]=15) and (x[i]<0) and (x[i]>-14)) or
              ((y[i]=-15) and (x[i]<0) and (x[i]>-14))

我认为第一个y [i] = 15应该是一个不等式,并且不等式应该包括相等作为一个选项,以便检测矩形角上的点。

      else if ((x[i]=0) and (y[i]<=15) and (y[i]>=-15)) or
              ((x[i]=-14) and (y[i]<=15) and (y[i]>=-15)) or
              ((y[i]=15) and (x[i]<=0) and (x[i]>=-14)) or
              ((y[i]=-15) and (x[i]<=0) and (x[i]>=-14))