Distance between Incenter and Circumcenter of a triangle using Inradius and Circumradius
Given two integers r and R representing the length of Inradius and Circumradius respectively, the task is to calculate the distance d between Incenter and Circumcenter.
Inradius The inradius( r ) of a regular triangle( ABC ) is the radius of the incircle (having center as l), which is the largest circle that will fit inside the triangle.
Circumradius: The circumradius( R ) of a triangle is the radius of the circumscribed circle (having center as O) of that triangle.
Input: r = 2, R = 5
Input: r = 5, R = 12
The problem can be solved using Euler’s Theorem in geometry, which states that the distance between the incenter and circumcenter of a triangle can be calculated by the equation:
Below is the implementation of the above approach:
Time Complexity: O(logn) since time complexity of sqrt is O(logn)
Auxiliary Space: O(1)