Largest sphere that can be inscribed within a cube which is in turn inscribed within a right circular cone | Function to find the radius of the sphere ; height and radius cannot be negative ; radius of the sphere ; Driver code
< ? php function sphereSide ( $ h , $ r ) { if ( $ h < 0 && $ r < 0 ) return -1 ; $ R = ( ( $ h * $ r * sqrt ( 2 ) ) / ( $ h + sqrt ( 2 ) * $ r ) ) / 2 ; return $ R ; } $ h = 5 ; $ r = 6 ; echo ( sphereSide ( $ h , $ r ) ) ; ? >