Skip to content
Related Articles

Related Articles

Find interior angles for each side of a given Cyclic Quadrilateral
  • Last Updated : 21 Apr, 2021

Given four positive integers A, B, C, and D representing the sides of a Cyclic Quadrilateral, the task is to find all the interior angles of the cyclic quadrilateral.

A cyclic quadrilateral is a quadrilateral whose vertices lie on a single circle. 
This circle is called the circumcircle or circumscribed circle, and the vertices are said to be concyclic(A, B, C, and D). 
( In the figure, r is the circumradius and a, b, c, and d are length of AB, BC, CD, and DA respectively).

Examples:

Input: A = 10, B = 15, C = 20, D = 25
Output:
∠A: 85.59 degrees
∠B: 122.58 degrees
∠C: 94.41 degrees
∠D: 57.42 degrees



Input: A = 10, B = 10, C = 10, D = 10
Output:
∠A: 90.00 degrees
∠B: 90.00 degrees
∠C: 90.00 degrees
∠D: 90.00 degrees

Approach: The given problem can be solved by using the formula to calculate the cosine of the interior angle of a cyclic quadrilateral. The formula is given by:

cos(A) = \frac{(a^2 + d^2 - b^2 - c^2)}{(2 *( a * b + c * d))}

cos(B) = \frac{(a^2 + b^2 - c^2 - d^2)}{(2 *( a * b + c * d))}

cos(C) = \frac{(c^2 + b^2 - a^2 - d^2)}{(2 *( a * b + c * d))}

cos(D) = \frac{(d^2 + c^2 - a^2 - b^2)}{(2 *( a * b + c * d))}

Follow the steps below to solve the problem:

Below is the implementation of the above approach:

C++




// C++ program for the above approach
#include <bits/stdc++.h>
using namespace std;
 
// Function to find the interior angles
// of the cyclic quadrilateral
void findAngles(double a, double b,
                double c, double d)
{
    // Stores the numerator and the
    // denominator to find angle A
    double numerator = a * a + d * d
                       - b * b - c * c;
 
    double denominator = 2 * (a * b + c * d);
 
    double x = numerator / denominator;
 
    cout << fixed << setprecision(2)
         << "A: " << (acos(x) * 180) / 3.141592
         << " degrees";
 
    // Stores the numerator and the
    // denominator to find angle B
    numerator = a * a + b * b
                - c * c - d * d;
 
    x = numerator / denominator;
 
    cout << fixed << setprecision(2)
         << "\nB: " << (acos(x) * 180) / 3.141592
         << " degrees";
 
    // Stores the numerator and the
    // denominator to find angle C:
    numerator = c * c + b * b
                - a * a - d * d;
 
    x = numerator / denominator;
 
    cout << fixed << setprecision(2)
         << "\nC: " << (acos(x) * 180) / 3.141592
         << " degrees";
 
    // Stores the numerator and the
    // denominator to find angle D:
    numerator = d * d + c * c
                - a * a - b * b;
 
    x = numerator / denominator;
 
    cout << fixed << setprecision(2)
         << "\nD: " << (acos(x) * 180) / 3.141592
         << " degrees";
}
 
// Driver Code
int main()
{
    double A = 10, B = 15, C = 20, D = 25;
    findAngles(A, B, C, D);
 
    return 0;
}

Java




// Java program for the above approach
class GFG{
     
// Function to find the interior angles
// of the cyclic quadrilateral
static void findAngles(double a, double b,
                       double c, double d)
{
     
    // Stores the numerator and the
    // denominator to find angle A
    double numerator = a * a + d * d -
                       b * b - c * c;
 
    double denominator = 2 * (a * b + c * d);
 
    double x = numerator / denominator;
 
    System.out.println("A: " +
       Math.round(((Math.acos(x) * 180) /
                       3.141592) * 100.0) /
                       100.0 + " degrees");
 
    // Stores the numerator and the
    // denominator to find angle B
    numerator = a * a + b * b - c * c - d * d;
 
    x = numerator / denominator;
 
    System.out.println("B: " +
       Math.round(((Math.acos(x) * 180) /
                       3.141592) * 100.0) /
                       100.0 + " degrees");
 
    // Stores the numerator and the
    // denominator to find angle C:
    numerator = c * c + b * b -
                a * a - d * d;
 
    x = numerator / denominator;
 
    System.out.println("C: " +
       Math.round(((Math.acos(x) * 180) /
                       3.141592) * 100.0) /
                       100.0 + " degrees");
 
    // Stores the numerator and the
    // denominator to find angle D:
    numerator = d * d + c * c -
                a * a - b * b;
 
    x = numerator / denominator;
 
    System.out.println("D: " +
       Math.round(((Math.acos(x) * 180) /
                       3.141592) * 100.0) /
                       100.0 + " degrees");
}
 
// Driver Code
public static void main (String[] args)
{
    double A = 10, B = 15, C = 20, D = 25;
     
    findAngles(A, B, C, D);
}
}
 
// This code is contributed by AnkThon

Python3




# Python3 program for the above approach
import math
 
# Function to find the interior angles
# of the cyclic quadrilateral
def findAngles(a, b, c, d):
     
    # Stores the numerator and the
    # denominator to find angle A
    numerator = a * a + d * d - b * b - c * c
    denominator = 2 * (a * b + c * d)
    x = numerator / denominator
    print("A: ", '%.2f' % ((math.acos(x) * 180) /
          3.141592), " degrees")
     
    # Stores the numerator and the
    # denominator to find angle B
    numerator = a * a + b * b - c * c - d * d
    x = numerator / denominator
    print("B: ", '%.2f' % ((math.acos(x) * 180) /
          3.141592), " degrees")
     
    # Stores the numerator and the
    # denominator to find angle C:
    numerator = c * c + b * b - a * a - d * d
    x = numerator / denominator
    print("C: ", '%.2f' % ((math.acos(x) * 180) /
          3.141592), " degrees")
     
    # Stores the numerator and the
    # denominator to find angle D:
    numerator = d * d + c * c - a * a - b * b
    x = numerator / denominator
    print("D: ", '%.2f' % ((math.acos(x) * 180) /
          3.141592), " degrees")
     
# Driver Code
if __name__ == "__main__":
     
    A = 10
    B = 15
    C = 20
    D = 25
     
    findAngles(A, B, C, D)
 
# This code is contributed by ukasp

C#




// C# program for the above approach
using System;
 
class GFG{
     
// Function to find the interior angles
// of the cyclic quadrilateral
static void findAngles(double a, double b,
                       double c, double d)
{
     
    // Stores the numerator and the
    // denominator to find angle A
    double numerator = a * a + d * d -
                       b * b - c * c;
 
    double denominator = 2 * (a * b + c * d);
 
    double x = numerator / denominator;
 
    Console.WriteLine("A: " +
       Math.Round(((Math.Acos(x) * 180) /
                       3.141592) * 100.0) /
                       100.0 + " degrees");
 
    // Stores the numerator and the
    // denominator to find angle B
    numerator = a * a + b * b - c * c - d * d;
 
    x = numerator / denominator;
 
    Console.WriteLine("B: " +
       Math.Round(((Math.Acos(x) * 180) /
                       3.141592) * 100.0) /
                       100.0 + " degrees");
 
    // Stores the numerator and the
    // denominator to find angle C:
    numerator = c * c + b * b -
                a * a - d * d;
 
    x = numerator / denominator;
 
    Console.WriteLine("C: " +
       Math.Round(((Math.Acos(x) * 180) /
                       3.141592) * 100.0) /
                       100.0 + " degrees");
 
    // Stores the numerator and the
    // denominator to find angle D:
    numerator = d * d + c * c -
                a * a - b * b;
 
    x = numerator / denominator;
 
    Console.WriteLine("D: " +
       Math.Round(((Math.Acos(x) * 180) /
                       3.141592) * 100.0) /
                       100.0 + " degrees");
}
 
// Driver Code
public static void Main(string[] args)
{
    double A = 10, B = 15, C = 20, D = 25;
     
    findAngles(A, B, C, D);
}
}
 
// This code is contributed by AnkThon

Javascript




<script>
 
// JavaScript program for the above approach
 
// Function to find the interior angles
// of the cyclic quadrilateral
function findAngles(a, b, c, d){
     
    // Stores the numerator and the
    // denominator to find angle A
    var numerator = a * a + d * d - b * b - c * c
    var denominator = 2 * (a * b + c * d)
    var x = numerator / denominator
    document.write("A: ", Math.round(((Math.acos(x) * 180) /
                       3.141592) * 100) / 100.0, " degrees");
    document.write("<br>");
     
    // Stores the numerator and the
    // denominator to find angle B
    numerator = a * a + b * b - c * c - d * d
    x = numerator / denominator
    document.write("B: ",  Math.round(((Math.acos(x) * 180) /
          3.141592) * 100) / 100.0, " degrees");
    document.write("<br>");
     
    // Stores the numerator and the
    // denominator to find angle C:
    numerator = c * c + b * b - a * a - d * d
    x = numerator / denominator
    document.write("C: ", Math.round(((Math.acos(x) * 180) /
          3.141592)  * 100) / 100.0, " degrees");
    document.write("<br>");
     
    // Stores the numerator and the
    // denominator to find angle D:
    numerator = d * d + c * c - a * a - b * b
    x = numerator / denominator
    document.write("D: ", Math.round(((Math.acos(x) * 180) /
          3.141592)  * 100) / 100.0, " degrees");
}
     
// Driver Code   
var A = 10
var B = 15
var C = 20
var D = 25
     
findAngles(A, B, C, D)
 
// This code is contributed by AnkThon
 
</script>
Output: 
A: 85.59 degrees
B: 122.58 degrees
C: 94.41 degrees
D: 57.42 degrees

 

Time Complexity: O(1)
Auxiliary Space: O(1)

Attention reader! Don’t stop learning now. Get hold of all the important mathematical concepts for competitive programming with the Essential Maths for CP Course at a student-friendly price. To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.

My Personal Notes arrow_drop_up
Recommended Articles
Page :