如何找到矩形的中心坐标? [英] How to find the Center Coordinate of Rectangle?

查看:2257
本文介绍了如何找到矩形的中心坐标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



我目前使用以下公式。

 (x, y)=(x2 + x1)/ 2,(y2 + y1)/ 2 

正确的y坐标,但在x没有运气。

解决方案

 矩形的中心是mid矩形的对角线端点的点。 
这里的中点是((x1 + x2)/ 2,(y1 + y2)/ 2)。
表示xCenter =(x1 + x2)/ 2
yCenter =(y1 + y2)/ 2

让我知道你的代码。


I have drawn a rectangle. I know its (x1,y1) Top Left and (x2,y2) Bottom Right coordinates.. I also have the height h and width w of drawn rectangle.. How can I find the center coordinates (x,y) ?

I am currently using the following formula.

(x,y) = (x2 + x1)/2, (y2+y1)/2

It gives the correct y coordinate but no luck in x.

解决方案

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

Let me know your code.

这篇关于如何找到矩形的中心坐标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆