Skip to content

Instantly share code, notes, and snippets.

@lacikawiz
Created January 13, 2019 18:16
Show Gist options
  • Select an option

  • Save lacikawiz/b08eb30e06a26e404843e326c61c7afc to your computer and use it in GitHub Desktop.

Select an option

Save lacikawiz/b08eb30e06a26e404843e326c61c7afc to your computer and use it in GitHub Desktop.
Calculate center coordinates and radius of circle based on the coordinates of 3 points on the circumference

#How to find the parameters of a circle based on 3 points on circumference

I spent some hours with WolframAlpha, paper and a text editor to distill the mathematical formula to find the center coordinates of a circle and its radius. I tested it with a few random coordinates and it returned precise results each time.

I provide here a Go code for my testing. It's very trivial to convert it into any other language.

Laszlo

package main
import (
"fmt"
"math"
)
func main() {
x1:=1.91
y1:=1.06
x2:=3.28
y2:=9.69
x3:=8.24
y3:=1.16
D1:=y2-y1
D2:=y1-y3
D3:=y3-y2
D4:=x1-x2
D5:=x3-x1
D6:=x2-x3
S1:=x1*x1+y1*y1
S2:=x2*x2+y2*y2
S3:=x3*x3+y3*y3
T1:=2*(x3*D1+x2*D2+x1*D3)
x:=(D3*S1+D2*S2+D1*S3)/T1
y:=(D6*S1+D5*S2+D4*S3)/T1
r:=0.5*math.Sqrt(
(D4*D4+D1*D1)*
(D5*D5+D2*D2)*
(D6*D6+D3*D3)/
(x1*D3+x2*D2+x3*D1)/
(x1*D3+x2*D2+x3*D1))
fmt.Println("x= ",x,"y=",y,"r=",r)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment