VOOZH about

URL: https://www.geeksforgeeks.org/dsa/find-center-circle-using-endpoints-diameter/

⇱ Find the center of the circle using endpoints of diameter - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Find the center of the circle using endpoints of diameter

Last Updated : 20 Feb, 2023

Given two endpoint of diameter of a circle (x1, y1) and (x2, y2) find out the center of a circle. 
Examples : 
 

Input : x1 = -9, y1 = 3, and 
 x2 = 5, y2 = –7
Output : -2, –2

Input : x1 = 5, y1 = 3 and 
 x2 = –10 y2 = 4
Output : –2.5, 3.5


 


Midpoint Formula: 
The midpoint of two points, (x1, y2) and (x2, y2) is : M = ((x 1 + x 2) / 2, (y 1 + y 2) / 2) 
The center of the circle is the mid point of its diameter so we calculate the mid point of its diameter by using midpoint formula. 
 

👁 center of the circle using endpoints of diameter


 

Output : 
 

-2, -2

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

Comment