VOOZH about

URL: https://www.geeksforgeeks.org/computer-science-fundamentals/angle-between-a-pair-of-lines/

⇱ Angle between a Pair of Lines - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Angle between a Pair of Lines

Last Updated : 23 Jul, 2025

Given two integers M1 and M2 representing the slope of two lines intersecting at a point, the task is to find the angle between these two lines.

Examples:

Input: M1 = 1.75, M2 = 0.27
Output: 45.1455 degrees

Input: M1 = 0.5, M2 = 1.75
Output: 33.6901 degrees

Approach: If ? is the angle between the two intersecting lines, then the angle ? can be calculated by:

tan? = |(M2 - M1) / (1 + M1 * M2)|
=> ? = tan-1( |(M2 - M1) / (1 + M1 * M2)| )

Follow the steps below to solve the problem:

Below is the implementation of the above approach:


Output: 
45.1455

 

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

Comment