Number of rectangles in a circle of radius R | Function to return the total possible rectangles that can be cut from the circle ; Diameter = 2 * $Radius ; Square of diameter which is the square of the maximum length diagonal ; generate all combinations of a and b in the range ( 1 , ( 2 * Radius - 1 ) ) ( Both inclusive ) ; Calculate the Diagonal length of this rectangle ; If this rectangle 's Diagonal  Length is less than the  Diameter, it is a valid  rectangle, thus increment counter ; Radius of the circle
< ? php function countRectangles ( $ radius ) { $ rectangles = 0 ; $ diameter = 2 * $ radius ; $ diameterSquare = $ diameter * $ diameter ; for ( $ a = 1 ; $ a < 2 * $ radius ; $ a ++ ) { for ( $ b = 1 ; $ b < 2 * $ radius ; $ b ++ ) { $ diagonalLengthSquare = ( $ a * $ a + $ b * $ b ) ; if ( $ diagonalLengthSquare <= $ diameterSquare ) { $ rectangles ++ ; } } } return $ rectangles ; } $ radius = 2 ; $ totalRectangles ; $ totalRectangles = countRectangles ( $ radius ) ; echo $ totalRectangles , " ▁ rectangles ▁ can ▁ be ▁ " , " cut ▁ from ▁ a ▁ circle ▁ of ▁ Radius ▁ " , $ radius ; ? >