Given 3 non-collinear points in the 2D Plane P, Q and R with their respective x and y coordinates, find the circumcenter of the triangle.
Note: Circumcenter of a triangle is the centre of the circle, formed by the three vertices of a triangle. Note that three points can uniquely determine a circle.
Input : P(6, 0) Q(0, 0) R(0, 8) Output : The circumcenter of the triangle PQR is: (3, 4) Input : P(1, 1) Q(0, 0) R(2, 2) Output : The two perpendicular bisectors found come parallel. Thus, the given points do not form a triangle and are collinear
Given, three points of the triangle, we can easily find the sides of the triangle. Now, we have the equations of the lines for the three sides of the triangle. After getting these, we can find the circumcenter of the triangle by a simple property stated as under:
The circumcenter of the triangle is point where all the perpendicular bisectors of the sides of the triangle intersect.
This is well explained in the following diagram.
Note here that, there is no need to find all of the three sides of the triangle. Finding two sides is sufficient as we can uniquely find the point of intersection using just two perpendicular bisectors. The third perpendicular bisector will itself pass through the so found circumcenter.
The things to be done can be divided as under:
- Find 2 lines (say PQ and QR) which form the sides of the triangle.
- Find the perpendicular bisectors of PQ and QR (say lines L and M respectively).
- Find the point of intersection of lines L and M as the circumcenter of the given triangle.
Refer this post Program to find line passing through 2 Points
Let PQ be represented as ax + by = c
A line perpendicular to this line is represented as -bx + ay = d for some d.
However, we are interested in the perpendicular bisector. So, we find the mid-point of P and Q and putting this value in the standard equation, we get the value of d.
Similarly, we repeat the process for QR.
d = -bx + ay where, x = (xp + xq)/2 AND y = (yp + yq)/2
Refer this post Program for Point of Intersection of Two Lines
The circumcenter of the triangle PQR is: (3, 4)
This article is contributed by Aanya Jindal. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Program to find area of a triangle
- Program to find the Centroid of the triangle
- Program to Find the Incenter of a Triangle
- Program to find the Radius of the incircle of the triangle
- Program to find third side of triangle using law of cosines
- Program to find the Type of Triangle from the given Coordinates
- Program to find Area of Triangle inscribed in N-sided Regular Polygon
- Program to print Sum Triangle for a given array
- Program for incrementing/decrementing triangle pattern
- Program to calculate area and perimeter of equilateral triangle
- Program to calculate area of Circumcircle of an Equilateral Triangle
- Find Perimeter of a triangle
- Find all angles of a triangle in 3D
- Find all angles of a given triangle
- Program to calculate the Area and Perimeter of Incircle of an Equilateral Triangle