Why divide by 4?


Within drawRect we have:

hypot(x,y)/4 == I assume that hypot is the hypotenuse of the triangle and thus is equal to the sqrt of (x^2 + y^2). I am missing why we divide by 4.0. Can anyone help … seems that we would be taking the square root of the sum and then divide by 2 to get the radius. What am I missing?



i figured it out by looking at doc.


Can srbjwe or anyone else please elaborate? Unfortunately, I did not figure it out from looking at the doc.

While the value of hypot(w, h) / 4 is a bit less than min(w, h) / 2, I would have gone with the latter over the former for a max radius from the center of a rectangle. What geometric relationship (if any) exists in a quarter the length of the hypotenuse?


Perhaps to draw their nifty olive.


I’m wondering this too.

Is it to do with how we calculate a circle mathematically?

Please can someone elaborate for us?

Thank you.


The comment about the docs may be misleading. The divide by 4 is just there to fit the circle inside the view rectangle.

If you instead use triangle legs of half width and half height, then the circle radius would be the half diagonal of the rectangle. And then the circle would be too big, only just touching the corners of the rectangle.

Note that there’s nothing special about the 4. You just want to fit your radius inside the view rectangle. You could have also divided by 5 or something.

If you want more of an exact fit, you can use the lesser of the half-width compared to the half-height. For example …

float maxRadius = 0.0;
float xLeg = bounds.size.width / 2.0;
float yLeg = bounds.size.height / 2.0;
if (xLeg < yLeg) {
     maxRadius = xLeg;
 } else {
     maxRadius =  yLeg;


I agree: calculating based on the hypotenuse and dividing by the arbitrary number 4 to make it kind of fit is just awkward. Maybe they just wanted to show you there are math functions.

Personally, I just calculated the size of the view and subtracted the point size of the circle’s brush.