如何找到矩形的中心坐标?

cas*_*123 31 math geometry formula

我画了一个矩形.我知道它的(x1,y1)左上角和(x2,y2)右下角坐标..我也有绘制矩形的高度h和宽度w.我怎样才能找到中心坐标(x,y)?

我目前正在使用以下公式.

(x,y) = (x2 + x1)/2, (y2+y1)/2
Run Code Online (Sandbox Code Playgroud)

它给出了正确的y坐标,但在x中没有运气.

Pra*_*d G 54

The center of rectangle is the mid point of the diagonal end points of rectangle. 
Here the midpoint is ( (x1 +x2)/2 ,(y1 + y2)/2 ).
that means xCenter = (x1 +x2)/2
           yCenter = (y1 + y2)/2
Run Code Online (Sandbox Code Playgroud)

让我知道你的代码.

  • 我认为它也可以是 - ( (x1*2)/2 , (y1*2)/2 ) (2认同)

小智 20

中心x =
x + 1/2宽度
中心y =
y + 1/2高度

如果您已经知道宽度和高度,那么您只需要一组坐标.