0
$\begingroup$

I'm writing a program in C++ to calculate the boundary box of a circle. The user provides me with a coordinate point (10, -5) and a radius of 23. I'm not very good at geometry and I need help in calculating the bounding box of this circle. How would I calculate this?

$\endgroup$
  • 1
    $\begingroup$ What do you mean by bounding box? The square in which the circle is inscribed? What do you mean by "calculate" it? Do you want the equation? An array of points? Is the user provided coordinate point the center of the circle? Note that if you want a code specific answer stackoverflow might be a better place to ask. $\endgroup$ – Quantaliinuxite Jul 16 '17 at 22:01
  • $\begingroup$ I'm not looking for code specific answers. Yes the points represents the centre of the circle. en.wikipedia.org/wiki/Minimum_bounding_box $\endgroup$ – ekeith Jul 16 '17 at 22:05
3
$\begingroup$

By bounding box I'm assuming you mean the box (square) in which the circle is inscribed, like in this picture:

enter image description here

Notice that the radius of the circle is exactly half the length of a side of the square.

So if the center of the circle is $(10,-5)$ and the radius of the circle is $23$, and if we're assuming a standard coordinate system ($y$-values increase in the up direction and $x$-values increase in the right direction), then the corners of the box are located at the following points:

\begin{align*} \text{upper left corner} &= (10-23, -5+23)\\ &= (-13, 18)\\[0.3cm] \text{upper right corner} &= (10+23, -5+23)\\ &= (33, 18)\\[0.3cm] \text{lower right corner} &= (10+23, -5-23)\\ &= (33, -28)\\[0.3cm] \text{lower left corner} &= (10-23, -5-23)\\ &= (-13, -28) \end{align*}

$\endgroup$
  • $\begingroup$ Thanks, was able to translate this to my code $\endgroup$ – ekeith Jul 16 '17 at 22:26
1
$\begingroup$

Let us assume that the bounding box' sides are parallel to the coordinate axes. Then you just need to go 23 steps in every direction, so you'd get the square with the points

$$(10+23,-5+23),(10+23,-5-23),(10-23,-5+23),(10-23,-5-23)$$

i.e.

$$(33,18),(33,-28),(-13,18),(-13,-28)$$

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.