+ 2

How can i calculate needed radius to fill a rectangle with a circle using rectangles width and height?

I'm working on a scene transition for a game and I plan on this to be on different sized screens. I can get the width and height in pixels but I want to grow the circle outward and stop when it fills the entire screen. A bit of a math question and that's definitely not my best subject. I hope this made sense and any help is greatly appreciated.

24th Jul 2017, 8:59 AM
Jordan Chapman
Jordan Chapman - avatar
6 ответов
+ 3
Found the answer, it is: radius = sqrt(width * width + height * height) / 2;
24th Jul 2017, 9:13 AM
Jordan Chapman
Jordan Chapman - avatar
+ 3
I would have say r = sqrt(hw^2 + hh^2) Were hw = width/2 and hh= height /2 😊
24th Jul 2017, 9:47 AM
Drax
Drax - avatar
+ 3
Drax's answer works but I don't think it's more accurate, when I tested mine it worked out perfectly and also gets the distance diagonally.
24th Jul 2017, 8:05 PM
Jordan Chapman
Jordan Chapman - avatar
+ 1
Drax's answer is more accurate, assuming we understood the question correctly (you want the circle diameter to be the diagonal of the screen)
24th Jul 2017, 2:44 PM
Bogdan Sass
Bogdan Sass - avatar
+ 1
Just tried and both seems to work perfectly. Jordan's answer might be a little bit non-formal but still works 😊
24th Jul 2017, 8:10 PM
Drax
Drax - avatar
+ 1
My bad - the resulting value is precisely the same :) sqrt( (w/2)^2 + (h/2)^2 ) == sqrt ( (w^2+h^2) / 4 ) == sqrt ( w^2+h^2 ) / 2 :)
24th Jul 2017, 8:23 PM
Bogdan Sass
Bogdan Sass - avatar