The Wayback Machine - https://web.archive.org/web/20240616022651/https://www.geeksforgeeks.org/find-the-angle-between-tangents-drawn-from-a-given-external-point-to-a-circle/
Open In App

Find the angle between tangents drawn from a given external point to a Circle

Last Updated : 19 Oct, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

Given a positive integer R representing the radius of the circle and the center of the circle (X1, Y1) and another point (X2, Y2) in the cartesian plane, the task is to find the angle between the pair of tangents drawn from the point (X2, Y2) to the circle.

Examples:

Input: R = 6, (X1, Y1) = (5, 1), (X2, Y2) = (6, 9)
Output: 96.1851

Input: R = 4, (X1, Y1) = (7, 12), (X2, Y2) = (3, 4)
Output: 53.1317

Approach: The given problem can be solved based on the following observations:

  • The radius makes an angle of 90 degrees with the tangent at the point of contact of the tangent and circle. Also, the angle subtended by the pair of tangents (?) is bisected by the line joining the center of the circle and the exterior point.
  • Therefore, the distance between the center and the exterior point can be calculated using the distance formula as:

Distance = \sqrt((x_2 - x_1)^2 + (y_2 - y_1)^2)

Now, consider d as the distance between the two given points, then In the right-angled triangle OAB,

=> sin (\frac{\theta}{2}) = \frac{OB}{OA}

=> sin (\frac{\theta}{2}) = \frac{r}{d}

=> \frac{\theta}{2} = sin^{-1}(\frac{r}{d})

=> \theta = 2*sin^{-1}(\frac{r}{d})

Therefore, using the above formula, the angle between the pair of tangents drawn from the point (X2, Y2) to the circle can be calculated.

Below is the implementation of the above approach:

C++

// C++ program for the above approach
 
#include <cmath>
#include <iostream>
using namespace std;
 
// Function to find the distance between
// center and the exterior point
double point_distance(int x1, int y1,
                      int x2, int y2)
{
    // Find the difference between
    // the x and y coordinates
    int p = (x2 - x1);
    int q = (y2 - y1);
 
    // Using the distance formula
    double distance = sqrt(p * p
                           + q * q);
 
    return distance;
}
 
// Function to find the angle between
// the pair of tangents drawn from the
// point (X2, Y2) to the circle.
void tangentAngle(int x1, int y1,
                  int x2, int y2,
                  double radius)
{
    // Calculate the distance between
    // the center and exterior point
    double distance = point_distance(
        x1, y1, x2, y2);
 
    // Invalid Case
    if (radius / distance > 1
        || radius / distance < -1) {
        cout << -1;
    }
 
    // Find the angle using the formula
    double result
        = 2 * asin(radius / distance) * 180
          / 3.1415;
 
    // Print the resultant angle
    cout << result << " degrees";
}
 
// Driver Code
int main()
{
    int radius = 4;
    int x1 = 7, y1 = 12;
    int x2 = 3, y2 = 4;
    tangentAngle(x1, y1, x2, y2, radius);
 
    return 0;
}

                    

Java

// java program for the above approach
import java.io.*;
import java.lang.*;
import java.util.*;
 
class GFG
{
   
// Function to find the distance between
// center and the exterior point
static double point_distance(int x1, int y1,
                      int x2, int y2)
{
    // Find the difference between
    // the x and y coordinates
    int p = (x2 - x1);
    int q = (y2 - y1);
  
    // Using the distance formula
    double distance = Math.sqrt(p * p
                           + q * q);
  
    return distance;
}
  
// Function to find the angle between
// the pair of tangents drawn from the
// point (X2, Y2) to the circle.
static void tangentAngle(int x1, int y1,
                  int x2, int y2,
                  double radius)
{
   
    // Calculate the distance between
    // the center and exterior point
    double distance = point_distance(
        x1, y1, x2, y2);
  
    // Invalid Case
    if (radius / distance > 1
        || radius / distance < -1) {
         System.out.println(-1);
    }
  
    // Find the angle using the formula
    double result
        = 2 * Math.asin(radius / distance) * 180
          / 3.1415;
  
    // Print the resultant angle
    System.out.println(String.format("%.4f", result) + " degrees");
}
   
    // Driver Code
    public static void main(String[] args)
    {
 
    int radius = 4;
    int x1 = 7, y1 = 12;
    int x2 = 3, y2 = 4;
    tangentAngle(x1, y1, x2, y2, radius);
    }
}
 
// This code is contributed by susmitakundugoaldanga.

                    

Python3

# Python 3 program for the above approach
import math
 
# Function to find the distance between
# center and the exterior point
def point_distance(x1, y1,
                   x2,  y2):
 
    # Find the difference between
    # the x and y coordinates
    p = (x2 - x1)
    q = (y2 - y1)
 
    # Using the distance formula
    distance = math.sqrt(p * p
                         + q * q)
 
    return distance
 
# Function to find the angle between
# the pair of tangents drawn from the
# point (X2, Y2) to the circle.
def tangentAngle(x1,  y1,
                 x2,  y2,
                 radius):
 
    # Calculate the distance between
    # the center and exterior point
    distance = point_distance(
        x1, y1, x2, y2)
 
    # Invalid Case
    if (radius / distance > 1
            or radius / distance < -1):
        print(-1)
 
    # Find the angle using the formula
    result = 2 * math.asin(radius / distance) * 180 / 3.1415
 
    # Print the resultant angle
    print(result, " degrees")
 
# Driver Code
if __name__ == "__main__":
 
    radius = 4
    x1 = 7
    y1 = 12
    x2 = 3
    y2 = 4
    tangentAngle(x1, y1, x2, y2, radius)
 
    # This code is contributed by ukasp.

                    

C#

// C# program for the above approach
using System;
 
class GFG{
 
// Function to find the distance between
// center and the exterior point
static double point_distance(int x1, int y1,
                             int x2, int y2)
{
     
    // Find the difference between
    // the x and y coordinates
    int p = (x2 - x1);
    int q = (y2 - y1);
 
    // Using the distance formula
    double distance = Math.Sqrt(p * p + q * q);
 
    return distance;
}
 
// Function to find the angle between
// the pair of tangents drawn from the
// point (X2, Y2) to the circle.
static void tangentAngle(int x1, int y1, int x2,
                         int y2, double radius)
{
 
    // Calculate the distance between
    // the center and exterior point
    double distance = point_distance(x1, y1, x2, y2);
 
    // Invalid Case
    if (radius / distance > 1 ||
        radius / distance < -1)
    {
        Console.WriteLine(-1);
    }
 
    // Find the angle using the formula
    double result = 2 * Math.Asin(
               radius / distance) *
                  180 / 3.1415;
 
    // Print the resultant angle
    Console.WriteLine(
        String.Format("{0:0.0000}", result) +
                      " degrees");
}
 
// Driver code
static void Main()
{
    int radius = 4;
    int x1 = 7, y1 = 12;
    int x2 = 3, y2 = 4;
     
    tangentAngle(x1, y1, x2, y2, radius);
}
}
 
// This code is contributed by abhinavjain194

                    

Javascript

<script>
 
// JavaScript program for the above approach
 
 
// Function to find the distance between
// center and the exterior point
function  point_distance( x1,  y1, x2,  y2)
{
     
    // Find the difference between
    // the x and y coordinates
    var p = (x2 - x1);
    var q = (y2 - y1);
 
    // Using the distance formula
    var distance = Math.sqrt(p * p + q * q);
 
    return distance;
}
 
// Function to find the angle between
// the pair of tangents drawn from the
// point (X2, Y2) to the circle.
 
function tangentAngle( x1,  y1,  x2, y2,  radius)
{
 
    // Calculate the distance between
    // the center and exterior point
    var distance = point_distance(x1, y1, x2, y2);
 
    // Invalid Case
    if (radius / distance > 1 ||
        radius / distance < -1)
    {
        document.write(-1 + "<br>");
    }
 
    // Find the angle using the formula
    var result = 2 * Math.asin(
               radius / distance) *
                  180 / 3.1415;
 
    // Print the resultant angle
    document.write( result.toFixed(4) + " degrees");
     
}
 
// Driver code
 
    var radius = 4;
    var x1 = 7, y1 = 12;
    var x2 = 3, y2 = 4;
     
    tangentAngle(x1, y1, x2, y2, radius);
     
</script>

                    

Output: 
53.1317 degrees

 

Time Complexity: O(logn) where n = (x2-x1)2+(y2-y1)2, because using inbuilt sqrt function
Auxiliary Space: O(1)



Similar Reads

Theorem - The lengths of tangents drawn from an external point to a circle are equal - Circles | Class 10 Maths
Tangent is a straight line drawn from an external point that touches a circle at exactly one point on the circumference of the circle. There can be an infinite number of tangents of a circle. These tangents follow certain properties that can be used as identities to perform mathematical computations on circles. Here, in this article, we will learn
5 min read
Angle subtended by the chord to center of the circle when the angle subtended by the another equal chord of a congruent circle is given
Given are two congruent circles with two equal chords. The angle subtended to the center from the chord of one of the circles is given. The task is to find the angle subtended by the chord to the center of another circle.Examples: Input: z = 48 Output: 48 degrees Input: z = 93 Output: 93 degrees Approach: In triangle AOB and PXQ AO = PX(radii of co
3 min read
Nth angle of a Polygon whose initial angle and per angle increment is given
Given four integers N, A, K, n where N represents the number of sides the polygon, A represents the initial angle of the polygon, K represents the per angle increase, the task is to find the nth angle of the polygon having N sides. If it is not possible then print -1. Examples: Input: N = 3, A = 30, K = 30, n = 3Output: 90Explanation:The 3rd angle
6 min read
Number of Tangents from a Point on a Circle
A circle is a collection of all the points in a plane that are at a constant distance from a particular point. This distance is called the radius of the circle and the fixed point is called the centre. A straight line and a circle can co-exist in three ways, one can be a straight line with no intersection to the circumference of the circle, there a
7 min read
Ratio of the distance between the centers of the circles and the point of intersection of two direct common tangents to the circles
Given two circles of given radii, such that the circles don’t touch each other, the task is to find the ratio of the distance between the centers of the circles and the point of intersection of two direct common tangents to the circles. Examples: Input: r1 = 4, r2 = 6 Output: 2:3 Input: r1 = 22, r2 = 43 Output: 22:43 Approach: Let the radii of the
5 min read
Ratio of the distance between the centers of the circles and the point of intersection of two transverse common tangents to the circles
Given two circles, of given radii, such that the circles don’t touch each other. The task is to find the ratio of the distance between the centres of the circles and the point of intersection of two transverse common tangents to the circles.Examples: Input :r1 = 4, r2 = 8 Output :1:2 Input :r1 = 5, r2 = 13 Output :5:13 Approach: Let the radii of th
5 min read
Angle between a chord and a tangent when angle in the alternate segment is given
Given a circle whose chord and tangent meet at a particular point. The angle in the alternate segment is given. The task here is to find the angle between the chord and the tangent.Examples: Input: z = 48 Output: 48 degrees Input: z = 64 Output: 64 degrees Approach: Let, angle BAC is the given angle in the alternate segment.let, the angle between t
3 min read
Constructions of Tangents to a Circle
A line can pass through a circle in three ways- it can either pass through only a single point of the circle, intersect it, or it can pass outside it. A line passing through a single point of a circle is called a tangent. When a line intersects the circle at two points, we call that line a tangent. Architects and designers use this concept every da
5 min read
Angle subtended by the chord when the angle subtended by another chord of same length is given
Given a circle having two chords of equal length. The angle subtended by one of the chords to the centre is given. The task here is to find the measure of the angle subtended by another chord at the centre.Examples: Input: 48 Output: 48 degrees Input: 82 Output: 82 degrees Approach: Let AC &amp; BD are the two equal chords of the circle having cent
3 min read
Exterior angle of a cyclic quadrilateral when the opposite interior angle is given
Given cyclic quadrilateral inside a circle, the task is to find the exterior angle of the cyclic quadrilateral when the opposite interior angle is given.Examples: Input: 48 Output: 48 degrees Input: 83 Output: 83 degrees Approach: Let, the exterior angle, angle CDE = xand, it's opposite interior angle is angle ABCas, ADE is a straight lineso, angle
3 min read