Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find the Center Coordinate of Rectangle? [closed]

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.

like image 809
casper123 Avatar asked Mar 16 '12 09:03

casper123


People also ask

How do you find the center coordinate?

If the coordinates of the endpoints of the diameter are (8, -7) and (4, 5), then the coordinates of the center of the circle can be calculated using the midpoint formula: (h, k) = [(x1 + x2]/2, [y1 + y2]/2). Therefore, the coordinates of the center are (6, -1).

What are the coordinates for a rectangle?

Use the rectangular coordinate system to uniquely identify points in a plane using ordered pairs (x,y). Ordered pairs indicate position relative to the origin. The x-coordinate indicates position to the left and right of the origin. The y-coordinate indicates position above or below the origin.

How do you find the center coordinates of a square?

Because it's a square, you can find the center by taking the average of the x coordinates of the corners, and then take the average of the y coordinates of the corners. This will give you the x and y coordinates of the center of the square.


1 Answers

The center of rectangle is the midpoint 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.

like image 196
Prasad G Avatar answered Nov 01 '22 21:11

Prasad G