SoatDev IT Consulting
SoatDev IT Consulting
  • About us
  • Expertise
  • Services
  • How it works
  • Contact Us
  • News
  • June 18, 2023
  • Rss Fetcher

Three given points on a circle with unknown center

A few months ago I wrote about several equations that come up in geometric calculations that all have the form of a determinant equal to 0, where one column of the determinant is all 1s.

The equation of a circle through three points (x1, y1), (x2, y2), and (x3, y3) has this form:

begin{vmatrix} x^2 + y^2 & x & y & 1 \ x_1^2 + y_1^2 & x_1 & y_1 & 1 \ x_2^2 + y_2^2 & x_2 & y_2 & 1 \ x_3^2 + y_3^2 & x_3 & y_3 & 1 \ end{vmatrix} = 0

This is elegant equation, but it’s not in a form that’s ready to program. This post will start with the equation above and conclude with code.

Let Mij be the determinant of the minor of the (i, j) element of the matrix above. That is, Mij is the determinant of the 3 × 3 matrix obtained by deleting the ith row and jth column. Then we can expand the determinant above by minors of the last column to get

M_{11}(x^2 + y^2) - M_{12}x + M_{13}y - M_{14} = 0

which we can rewrite as

x^2 + y^2 -frac{M_{12}}{M_{11}} x + frac{M_{13}}{M_{11}} y - frac{M_{14}}{M_{11}} = 0.

A circle with center (x0, y0) and radius r0 has equation

(x - x_0)^2 + (y - y_0)^2 - r_0^2 = 0.

By equating the coefficients x and y in the two previous equations we have

begin{align*} x_0 &= phantom{-}frac{1}{2} frac{M_{12}}{M_{11}} \ y_0 &= -frac{1}{2} frac{M_{13}}{M_{11}} \ end{align*}

Next we expand the determinant minors in more explicit form.

begin{align*} M_{11} &= begin{vmatrix} x_1 & y_1 & 1 \ x_2 & y_2 & 1 \ x_3 & y_3 & 1 \ end{vmatrix} \ &= (x_2y_3 - x_3y_2) - (x_1y_3 - x_3y_1) + (x_1y_2 - x_2y_1) \ &= (x1y_2 + x_2y_3 + x_3y_1) - (x_2y_1 + x_3y_2 + x_1y_3) end{align*}

Having gone to the effort of finding a nice expression for M11 we can reuse it to find M12 by the substitution

x_i to s_i equiv x_i^2 + y_i^2

as follows:

begin{align*} M_{12} &= begin{vmatrix} x_1^2 + y_1^2 & y_1 & 1 \ x_2^2 + y_2^2 & y_2 & 1 \ x_3^2 + y_3^2 & y_3 & 1 \ end{vmatrix} = begin{vmatrix} s_1^2 & y_1 & 1 \ s_2^2 & y_2 & 1 \ s_3^2 & y_3 & 1 \ end{vmatrix} \ &= (s_1y_2 + s_2y_3 + s_3y_1) - (s_2y_1 + s_3y_2 + s_1y_3) end{align*}

And we can find M13 from M12 by reversing the role of the xs and ys.

begin{align*} M_{13} &= begin{vmatrix} x_1^2 + y_1^2 & x_1 & 1 \ x_2^2 + y_2^2 & x_2 & 1 \ x_3^2 + y_3^2 & x_3 & 1 \ end{vmatrix} = begin{vmatrix} s_1^2 & x_1 & 1 \ s_2^2 & x_2 & 1 \ s_3^2 & x_3 & 1 \ end{vmatrix} \ &= (s_1x_2 + s_2x_3 + s_3x_1) - (s_2x_1 + s_3x_2 + s_1x_3) end{align*}

Now we have concrete expressions for M11, M12, and M13, and these give us concrete expressions for x0 and y0.

To find the radius of the circle we simply find the distance from the center (x0, y0) to any of the points on the circle, say (x1, y1).

The following Python code incorporates the derivation above.

    def circle_thru_pts(x1, y1, x2, y2, x3, y3):
        s1 = x1**2 + y1**2
        s2 = x2**2 + y2**2
        s3 = x3**2 + y3**2
        M11 = x1*y2 + x2*y3 + x3*y1 - (x2*y1 + x3*y2 + x1*y3)
        M12 = s1*y2 + s2*y3 + s3*y1 - (s2*y1 + s3*y2 + s1*y3)
        M13 = s1*x2 + s2*x3 + s3*x1 - (s2*x1 + s3*x2 + s1*x3)
        x0 =  0.5*M12/M11
        y0 = -0.5*M13/M11
        r0 = ((x1 - x0)**2 + (y1 - y0)**2)**0.5
        return (x0, y0, r0)

The code doesn’t use any loops or arrays, so it ought to be easy to port to any programming language.

For some inputs the value of M11 can be (nearly) zero, in which case the three points (nearly) lie on a line. In practice M11 can be nonzero and yet zero for practical purposes and so that’s something to watch out for when using the code.

The determinant at the top of the post is zero when the points are colinear. There’s a way to make rigorous the notion that in this case the points line on a circle centered at infinity.

The post Equation of a circle through three points first appeared on John D. Cook.

Previous Post
Next Post

Recent Posts

  • Early AI investor Elad Gil finds his next big bet: AI-powered rollups
  • Fitting a parabola to an ellipse and vice versa
  • Sam Altman biographer Keach Hagey explains why the OpenAI CEO was ‘born for this moment’
  • Day 4 of TechCrunch Sessions: AI Trivia Countdown — Flex your brain, score big on tickets
  • Video game union announces first contract with Microsoft

Categories

  • Industry News
  • Programming
  • RSS Fetched Articles
  • Uncategorized

Archives

  • June 2025
  • May 2025
  • April 2025
  • February 2025
  • January 2025
  • December 2024
  • November 2024
  • October 2024
  • September 2024
  • August 2024
  • July 2024
  • June 2024
  • May 2024
  • April 2024
  • March 2024
  • February 2024
  • January 2024
  • December 2023
  • November 2023
  • October 2023
  • September 2023
  • August 2023
  • July 2023
  • June 2023
  • May 2023
  • April 2023

Tap into the power of Microservices, MVC Architecture, Cloud, Containers, UML, and Scrum methodologies to bolster your project planning, execution, and application development processes.

Solutions

  • IT Consultation
  • Agile Transformation
  • Software Development
  • DevOps & CI/CD

Regions Covered

  • Montreal
  • New York
  • Paris
  • Mauritius
  • Abidjan
  • Dakar

Subscribe to Newsletter

Join our monthly newsletter subscribers to get the latest news and insights.

© Copyright 2023. All Rights Reserved by Soatdev IT Consulting Inc.