Length of intercept cut off from a line by a Circle
Given six integers, a, b, c, i, j, and k representing the equation of the circle and equation of the line , the task is to find the length of the intercept cut off from the given line to the circle.
Input: a = 0, b = 0, c = -4, i = 2, j = -1, k = 1
Input: a = 5, b = 6, c = -16, i = 1, j = 4, k = 3
Approach: Follow the steps below to solve the problem:
- Find the center of the circle, say as and .
- The perpendicular from the center divides the intercept into two equal parts, therefore calculate the length of one of the parts and multiply it by 2 to get the total length of the intercept.
- Calculate the value of radius (r) using the formula: , where and
- Calculate the value of perpendicular distance ( d ) of center O from the line by using the formula:
- Now from the pythagoras theorem in triangle OCA:
- After completing the above steps, print the value of twice of AC to get the length of the total intercept.
Below is the implementation of the above approach:
Time Complexity: O(1)
Auxiliary Space: O(1)
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.