The Wayback Machine - https://web.archive.org/web/20240712152455/https://www.geeksforgeeks.org/distance-between-incenter-and-circumcenter-of-a-triangle-using-inradius-and-circumradius/
Open In App

Distance between Incenter and Circumcenter of a triangle using Inradius and Circumradius

Last Updated : 09 Sep, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

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. 

Examples: 

Input: r = 2, R = 5 
Output: 2.24

Input: r = 5, R = 12 
Output: 4.9

Approach: 
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:

Distance = \sqrt{R^2 - 2rR}


Below is the implementation of the above approach:

C++14

// C++14 program for the above approach
#include <bits/stdc++.h>
using namespace std;
 
// Function returns the required distance
double distance(int r, int R)
{
    double d = sqrt(pow(R, 2) -
                       (2 * r * R));
                             
    return d;
}
 
// Driver code
int main()
{
     
    // Length of Inradius
    int r = 2;
     
    // Length of Circumradius
    int R = 5;
 
    cout << (round(distance(r, R) * 100.0) / 100.0);
}
 
// This code is contributed by sanjoy_62

                    

Java

// Java program for the above approach
import java.util.*;
 
class GFG{
     
// Function returns the required distance
static double distance(int r,int R)
{
    double d = Math.sqrt(Math.pow(R, 2) -
                         (2 * r * R));
                          
    return d;
}
 
// Driver code
public static void main(String[] args)
{
     
    // Length of Inradius
    int r = 2;
     
    // Length of Circumradius
    int R = 5;
 
    System.out.println(Math.round(
        distance(r, R) * 100.0) / 100.0);
}
}
 
// This code is contributed by offbeat

                    

Python3

# Python3 program for the above approach
import math
 
# Function returns the required distance
def distance(r,R):
 
    d = math.sqrt( (R**2) - (2 * r * R))
     
    return d
 
# Driver Code
 
# Length of Inradius
r = 2
 
# Length of Circumradius
R = 5
 
print(round(distance(r,R),2))

                    

C#

// C# program for the above approach
using System;
 
class GFG{
     
// Function returns the required distance
static double distance(int r, int R)
{
    double d = Math.Sqrt(Math.Pow(R, 2) -
                         (2 * r * R));
                         
    return d;
}
 
// Driver code
public static void Main(string[] args)
{
     
    // Length of Inradius
    int r = 2;
     
    // Length of Circumradius
    int R = 5;
     
    Console.Write(Math.Round(
        distance(r, R) * 100.0) / 100.0);
}
}
 
// This code is contributed by rutvik_56

                    

Javascript

<script>
 
// Javascript program for
// the above approach
 
// Function returns the required distance
function distance(r, R)
{
    let d = Math.sqrt(Math.pow(R, 2) -
                         (2 * r * R));
                            
    return d;
}
 
// Driver code
 
    // Length of Inradius
    let r = 2;
       
    // Length of Circumradius
    let R = 5;
   
    document.write(Math.round(
        distance(r, R) * 100.0) / 100.0);
      
     // This code is contributed by susmitakundugoaldanga.
</script>

                    

Output: 
2.24


Time Complexity: O(logn) since time complexity of sqrt is O(logn)
Auxiliary Space: O(1)
 



Similar Reads

Distance between orthocenter and circumcenter of a right-angled triangle
Given three pairs of integers A(x, y), B(x, y), and C(x, y), representing the coordinates of a right-angled triangle, the task is to find the distance between the orthocenter and circumcenter. Examples: Input: A = {0, 0}, B = {5, 0}, C = {0, 12}Output: 6.5Explanation:Triangle ABC is right-angled at the point A. Therefore, orthocenter lies on the po
12 min read
Program to Find the Incenter of a Triangle
Given the vertices of a triangle and length of its sides. A circle is inscribed in a triangle. The task is to find the incenter of a triangle.Examples: Input: A(2, 2), B(1, 1), C(3, 1) Output: (2, 1.5) Input: A(3, 3), B(1, 2), C(2, 2) Output: (2.5, 2.83) Approach: The center of the circle that touches the sides of a triangle is called its incenter.
4 min read
Program to find Circumcenter of a Triangle
Given 3 non-collinear points in the 2D Plane P, Q and R with their respective x and y coordinates, find the circumcenter of the triangle.Note: Circumcenter of a triangle is the centre of the circle, formed by the three vertices of a triangle. Note that three points can uniquely determine a circle.Examples: Input : P(6, 0) Q(0, 0) R(0, 8) Output : T
13 min read
Circumradius of a Cyclic Quadrilateral using the length of Sides
Given integers A, B, C, and D denoting the length of sides of a Cyclic Quadrilateral, the task is to find the circumradius i.e., the radius of circumcircle of the given cyclic quadrilateral. Examples: Input: A = 3, B = 4, C = 5, D= 6Output: 3.29 Input: A = 10, B = 30, C = 50, D = 20Output: 27.78 Approach: Follow the steps below to solve the problem
5 min read
Circumradius of the rectangle
Here we have a rectangle of length l &amp; breadth b. We have to find the circumradius of the rectangle. Examples: Input : l = 3, b = 4 Output :2.5 Input :l = 10, b = 12 Output :3.95227774224 Approach: From the diagram, we can clearly understand the circumradius r is half of the diagonal of the rectangle. r = ?(l^2 + b^2)/2 Below is the implementat
5 min read
Distance of chord from center when distance between center and another equal length chord is given
Given two equal length chords of a circle and Distance between the centre and one chord. The task is here to find the distance between the centre and the other chord. Examples: Input: 48 Output: 48 Input: 82 Output: 82 Below is the implementation of the above approach:Approach: Let AB &amp; CD be the two equal chords of the circle having center at
3 min read
Generate string with Hamming Distance as half of the hamming distance between strings A and B
Given two Binary string A and B of length N, the task is to find the Binary string whose Hamming Distance to strings A and B is half the Hamming Distance of A and B.Examples: Input: A = "1001010", B = "0101010" Output: 0001010 Explanation: The hamming distance of the string A and B is 2. The hamming distance of the output string to A is 1. The hamm
7 min read
Calculate ratio of area of a triangle inscribed in an Ellipse and the triangle formed by corresponding points on auxiliary circle
Given two integers A and B representing the lengths of semi-major and semi-minor axes of an ellipse, the task is to calculate the ratio of any triangle inscribed in the ellipse and that of the triangle formed by the corresponding points on its auxiliary circle. Examples: Input: A = 1, B = 2Output: 2Explanation: Ratio = B / A = 2 / 1 = 2 Input: A =
4 min read
Sum of upper triangle and lower triangle
Given a N x M matrix. The task is to print the sum of upper and lower triangular elements (i.e elements on the diagonal and the upper and lower elements). Examples : Input: {{6, 5, 4}, {1, 2, 5}, {7, 9, 7}}Output:Upper sum is 29Lower sum is 32 Input: {{1, 1, 1}, {2, 2, 2}, {3, 3, 3}}Output:Upper sum is 10Lower sum is 14 Recommended Problem Sum of u
6 min read
Program to print a Hollow Triangle inside a Triangle
Given a number N(? 8), the task is to print a Hollow Triangle inside a Triangle pattern.Example: Input: N = 9 Output: * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Approach: Let i be the index for rows and j be the index for columns. Then: For sides of outer triangle: If the index of column(j) is equals to (N - i + 1) or (
7 min read
Article Tags :
Practice Tags :
three90RightbarBannerImg