[Math] Given 2 Points of a Rectangle, find the Center

geometry

In a feature that I am writing for a program, I need to find the (x, y) of the center of a rectangle while only being provided the (x, y) of the top left and bottom right corners. I've been out of a math course for awhile now and cannot thing of any equations that I can use to solve this. Here is a Paint image I drew up to show what I am working with. Note that the points are going to be dynamic, so the numbers won't ever be the same. If someone can point me in the right direction, that would be great!

Center of Rectangle with 2 corners

Best Answer

It's just the midpoint between the two corners. If the points are $(p_1,p_2)$ and $(q_1,q_2)$, then the midpoint is $$\left(\tfrac{p_1+q_1}2,\tfrac{p_2+q_2}2\right)$$ the coordinate-wise "average" of the two points.