2

I have a circle, say radius of 10, and I can find the outer bounding rect easy enough since its width and height is equal to the radius, but what I need is the inner bounding rect. Does anyone know how to calculate the difference in size from the outer and inner bounding rectangles of a circle?

Here's an image to illustrate what I'm talking about. The red rectangle is the outer bounding box of the circle, which I know. The yellow rectangle is the inner bounding rectangle of the circle, which I need to find the difference in size from the outer rectangle.

circle example

My first guess to find the difference is to find one of the four points of the inner rectangle by finding that point along the circumference of the circle, each point being at a 45 degree offsets, and then just find the different from that point and the related point in the larger rect.

EDIT: Based off of the solution given by Steve B. I've come up with the algorithm to get what I want which is the following:

r*2 - sqrt(2)*r
Justin G
  • 776
  • 1
  • 10
  • 25
  • 1
    belongs to http://math.stackexchange.com/ – Steve B Jan 03 '12 at 23:38
  • Oh, there's a math site? I didn't know. I am using this for programming though :P But I guess I'll post there if I have any other math related stuff. Thanks :) – Justin G Jan 03 '12 at 23:48

3 Answers3

5

If the radius is r, the outer rectangle size will be r*2.

The inner rectangle will have size equals to 2*sqrt(2*r).

So the diff will be equals to 2*(r-sqrt(2*r^2)).

Steve B
  • 36,818
  • 21
  • 101
  • 174
  • Thanks a lot. This is just what I needed. I thought I needed a sqrt() somewhere but wasn't sure where. – Justin G Jan 03 '12 at 23:51
  • Never mind, I had to make a slight adjustment to get what I wanted. Updating the main post with the solution I found. I'll still mark this as the solution though since it pointed me in the right direction. – Justin G Jan 04 '12 at 00:21
  • There is a mistake here!! How could you substract sqrt(meter) from meter?? See my answer - it has correct side length of the inner rectangle – Sasha Jan 04 '12 at 09:44
3

You know the size of the radius and you have a triangle with a corner of 90 degrees with one point as the center of your circle and another two as two corners of your inner square.

Now if you know two sides of a triangle you can use Pythagoras:

x^2 = a^2 + b^2
    = 2* r^2

So

x = sqrt(2 * r^2)

With r the radius of the circle, x the side of the square.

v1Axvw
  • 3,054
  • 3
  • 26
  • 40
0

It's simple geometry: Outer rectangle has length of edge equal to 2*R, inner - diagonal equal to 2*R. So the edge of inner rectangle is equal to sqrt(2)*R. The ratio of edges of outer rectangle divided by inner is obviously sqrt(2).

Sasha
  • 8,537
  • 4
  • 49
  • 76