Open In App

Radius of the biggest possible circle inscribed in rhombus which in turn is inscribed in a rectangle

Last Updated : 27 Aug, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

Give a rectangle with length l & breadth b, which inscribes a rhombus, which in turn inscribes a circle. The task is to find the radius of this circle.
Examples: 
 

Input: l = 5, b = 3
Output: 1.28624

Input: l = 6, b = 4
Output: 1.6641

 

 

Approach: From the figure, it is clear that diagonals, x & y, are equal to the length and breadth of the rectangle. 
Also radius of the circle, r, inside a rhombus is = xy/2?(x^2+y^2). 
So, radius of the circle in terms of l & b is = lb/2?(l^2+b^2).
Below is the implementation of the above approach
 

C++




// C++ implementation of above approach
#include <bits/stdc++.h>
using namespace std;
 
// Function to find the radius
// of the inscribed circle
float circleradius(float l, float b)
{
 
    // the sides cannot be negative
    if (l < 0 || b < 0)
        return -1;
 
    // radius of the circle
    float r = (l * b) / (2 * sqrt((pow(l, 2) + pow(b, 2))));
    return r;
}
 
// Driver code
int main()
{
    float l = 5, b = 3;
    cout << circleradius(l, b) << endl;
 
    return 0;
}


Java




// Java implementation of above approach
 
import java.io.*;
 
class GFG {
     
// Function to find the radius
// of the inscribed circle
static float circleradius(float l, float b)
{
 
    // the sides cannot be negative
    if (l < 0 || b < 0)
        return -1;
 
    // radius of the circle
    float r = (float)((l * b) / (2 * Math.sqrt((Math.pow(l, 2) + Math.pow(b, 2)))));
    return r;
}
 
    // Driver code
    public static void main (String[] args) {
        float l = 5, b = 3;
    System.out.print (circleradius(l, b)) ;
    }
}
// This code is contributed by inder_verma..


Python3




# Python 3 implementation of
# above approach
from math import sqrt
 
# Function to find the radius
# of the inscribed circle
def circleradius(l, b):
     
    # the sides cannot be negative
    if (l < 0 or b < 0):
        return -1
 
    # radius of the circle
    r = (l * b) / (2 * sqrt((pow(l, 2) +
                             pow(b, 2))));
    return r
 
# Driver code
if __name__ == '__main__':
    l = 5
    b = 3
    print("{0:.5}" . format(circleradius(l, b)))
 
# This code is contribute
# by Surendra_Gagwar


C#




// C# implementation of above approach
using System;
 
class GFG
{
     
// Function to find the radius
// of the inscribed circle
static float circleradius(float l,
                          float b)
{
 
    // the sides cannot be negative
    if (l < 0 || b < 0)
        return -1;
 
    // radius of the circle
    float r = (float)((l * b) /
              (2 * Math.Sqrt((Math.Pow(l, 2) +
                   Math.Pow(b, 2)))));
    return r;
}
 
// Driver code
public static void Main ()
{
    float l = 5, b = 3;
    Console.WriteLine(circleradius(l, b));
}
}
 
// This code is contributed
// by inder_verma


PHP




<?php
// PHP implementation of above approach
 
// Function to find the radius
// of the inscribed circle
function circleradius($l, $b)
{
 
    // the sides cannot be negative
    if ($l < 0 || $b < 0)
        return -1;
 
    // radius of the circle
    $r = ($l * $b) / (2 * sqrt((pow($l, 2) +
                                pow($b, 2))));
    return $r;
}
 
// Driver code
$l = 5;
$b = 3;
echo circleradius($l, $b), "\n";
 
// This code is contributed by ajit
?>


Javascript




<script>
// javascript implementation of above approach
 
// Function to find the radius
// of the inscribed circle
function circleradius(l , b)
{
 
    // the sides cannot be negative
    if (l < 0 || b < 0)
        return -1;
 
    // radius of the circle
    var r = ((l * b) / (2 * Math.sqrt((Math.pow(l, 2) + Math.pow(b, 2)))));
    return r;
}
 
var l = 5, b = 3;
document.write(circleradius(l, b).toFixed(5)) ;
 
// This code is contributed by shikhasingrajput
</script>


Output: 

1.28624

 

Time complexity: O(logn) as it is using inbuilt sqrt  function

Auxiliary Space: O(1) since using constant variables



Similar Reads

Area of the biggest possible rhombus that can be inscribed in a rectangle
Given a rectangle of length l and breadth b, the task is to find the largest rhombus that can be inscribed in the rectangle.Examples: Input : l = 5, b = 4 Output : 10 Input : l = 16, b = 6 Output : 48 From the figure, we can see, the biggest rhombus that could be inscribed within the rectangle will have its diagonals equal to the length &amp; bread
4 min read
Radii of the three tangent circles of equal radius which are inscribed within a circle of given radius
Given here is a circle of a given radius. Inside it, three tangent circles of equal radius are inscribed. The task is to find the radii of these tangent circles. Examples: Input: R = 4Output: 1.858 Input: R = 11Output: 5.1095 Approach: Let the radii of the tangent circles be r, and the radius of the circumscribing circle is R.x is the smaller dista
3 min read
Largest ellipse that can be inscribed within a rectangle which in turn is inscribed within a semicircle
Given here is a semicircle of radius r, which inscribes a rectangle which in turn inscribes an ellipse. The task is to find the area of this largest ellipse.Examples: Input: r = 5 Output: 19.625 Input: r = 11 Output: 94.985 Approach: Let the, length of the rectangle = l and breadth of the rectangle = bLet, the length of the major axis of the ellips
4 min read
The biggest possible circle that can be inscribed in a rectangle
Given a rectangle of length l &amp; breadth b, we have to find the largest circle that can be inscribed in the rectangle. Examples: Input : l = 4, b = 8 Output : 12.56 Input : l = 16 b = 6 Output : 28.26 From the figure, we can see, the biggest circle that could be inscribed in the rectangle will have radius always equal to the half of the shorter
4 min read
Area of a circle inscribed in a rectangle which is inscribed in a semicircle
Given a semicircle with radius R, which inscribes a rectangle of length L and breadth B, which in turn inscribes a circle of radius r. The task is to find the area of the circle with radius r.Examples: Input : R = 2 Output : 1.57 Input : R = 5 Output : 9.8125 Approach: We know the biggest rectangle that can be inscribed within the semicircle has, l
4 min read
Largest right circular cylinder that can be inscribed within a cone which is in turn inscribed within a cube
Given here is a cube of side length a, which inscribes a cone which in turn inscribes a right circular cylinder. The task is to find the largest possible volume of this cylinder.Examples: Input: a = 5 Output: 232.593 Input: a = 8 Output: 952.699 Approach: From the figure, it is very clear, height of cone, H = a and radius of the cone, R = a?2, plea
5 min read
Largest sphere that can be inscribed within a cube which is in turn inscribed within a right circular cone
Given here is a right circular cone of radius r and perpendicular height h, which is inscribed in a cube which in turn is inscribed in a sphere, the task is to find the radius of the sphere.Examples: Input: h = 5, r = 6 Output: 1.57306 Input: h = 8, r = 11 Output: 2.64156 Approach: Let the side of the cube = aLet the radius of the sphere = RWe know
4 min read
Biggest Reuleaux Triangle inscribed within a square which is inscribed within an ellipse
Given an ellipse with major axis length and minor axis 2a &amp; 2b respectively which inscribes a square which in turn inscribes a reuleaux triangle. The task is to find the maximum possible area of this reuleaux triangle.Examples: Input: a = 5, b = 4 Output: 0.0722389 Input: a = 7, b = 11 Output: 0.0202076 Approach: As, the side of the square insc
5 min read
Biggest Reuleaux Triangle inscribed within a square which is inscribed within a hexagon
Given a regular hexagon of side length a which inscribes a square which in turn inscribes a reuleaux triangle. The task is to find the maximum possible area of this reuleaux triangle.Examples: Input: a = 5 Output: 28.3287 Input: a = 9 Output: 91.7848 Approach: As the side of the square inscribed within a hexagon is x = 1.268a. Please refer Largest
4 min read
Biggest Reuleaux Triangle within a Square which is inscribed within a Circle
Given here is a circle of radius r, which inscribes a square which in turn inscribes a reuleaux triangle. The task is to find the maximum possible area of this reuleaux triangle.Examples: Input: r = 6 Output: 50.7434 Input: r = 11 Output: 170.554 Approach: From the figure, it is very clear that, if the side of the square is a, then a?2 = 2r a = ?2r
4 min read