+ 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.
6 Réponses
+ 3
Found the answer, it is:
radius = sqrt(width * width + height * height) / 2;
+ 3
I would have say
r = sqrt(hw^2 + hh^2)
Were hw = width/2 and hh= height /2
😊
+ 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.
+ 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)
+ 1
Just tried and both seems to work perfectly. Jordan's answer might be a little bit non-formal but still works 😊
+ 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
:)