作为象限一部分的 JPanel 的 x,y 坐标

x,y coordinates of a JPanel as part of a quadrant

我的程序有问题。我想要实现的是一种理解象限所在的点(x,y)的方法。

我要实现的象限概念如下:

我有一个矩形,从中我有所有角度和边的坐标。给定 space 中的另一个点,在 2D space 中,我想知道顶部、底部、左侧和右侧之间的位置。

提前致谢。

编辑:

到目前为止我已经写了这段代码:

Point A=t.src;  //center point of the first square
Point B=t.dest;  //center point of the second square

int destHeight=t.destDim.height;
int destWidth=t.destDim.width;

int m = destHeight/destWidth;
int b = B.y -(m*B.x);
int d = B.y +(m*B.x);

if(A.y >= m*A.x +b){
    if(A.y >= -m*A.x+d){
        System.err.println("2 - Source on BOTTOM");
    }else{ //A.y < -m*A.x+d
        System.err.println("2 - Source on LEFT");
    } 
}else if(A.y < m*A.x + b){
    if(A.y>= -m*A.x +d){
        System.err.println("2 - Source on RIGHT");
    }else{ //A.y < m*A.x + d
        System.err.println("2 - Source on TOP");
    }
}

问题是我仍然没有得到预期的结果。这就是我得到的: Video demo of the problem

正如您从输出控制台中看到的那样,它永远不会显示源在左侧,它只是从上到下过渡。

设矩形以零为中心,边长 a(水平)和 b。 (如果它不是以零为中心,只需从点坐标中减去中心坐标)。然后线条有简单的方程

m = b / a 
y = m * x   //L1
y = -m * x  //L2

上象限的点在两条线的上方,右象限的点在L2上方但在L1下方,依此类推。

对于点坐标(px, py):

 mpx = m * px
 if (py >= mpx) :
     if (py >= -mpx) :
          top
     else:
          left
 else:    
     if (py >= -mpx) :
          right
     else:
          bottom