Skip to content

Instantly share code, notes, and snippets.

@dhermes
Created March 4, 2015 04:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dhermes/9ce057da49df63345c33 to your computer and use it in GitHub Desktop.
Save dhermes/9ce057da49df63345c33 to your computer and use it in GitHub Desktop.
import numpy as np
def circumcenter(vert1, vert2, vert3):
# H/T: wikipedia.org/wiki/Circumscribed_circle
Ax, Ay = vert1
Bx, By = vert2
Cx, Cy = vert3
D = 2 * (Ax * (By - Cy) + Bx * (Cy - Ay) + Cx * (Ay - By))
norm_A = Ax**2 + Ay**2
norm_B = Bx**2 + By**2
norm_C = Cx**2 + Cy**2
Ux = norm_A * (By - Cy) + norm_B * (Cy - Ay) + norm_C * (Ay - By)
Uy = -(norm_A * (Bx - Cx) + norm_B * (Cx - Ax) + norm_C * (Ax - Bx))
return np.array([Ux, Uy]) / D
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment