Skip to content

Instantly share code, notes, and snippets.

@marmakoide
Last active April 13, 2018 11:55
Show Gist options
  • Save marmakoide/827b7d2cc40b264d17d0dd2278a218b2 to your computer and use it in GitHub Desktop.
Save marmakoide/827b7d2cc40b264d17d0dd2278a218b2 to your computer and use it in GitHub Desktop.
Computes the circumcircle of a triangle (assuming 2d coordinates), returning its center and its radius
import numpy
def norm2(X):
return numpy.sqrt(numpy.sum(X ** 2))
def get_circumcircle(A, B, C):
U, V = B - A, C - A
U_norm, V_norm = norm2(U), norm2(V)
U /= U_norm
V /= V_norm
UdV = numpy.dot(U, V)
D = numpy.array([U_norm - UdV * V_norm, V_norm - UdV * U_norm])
D /= 2. * (1. - UdV ** 2)
center = D[0] * U + D[1] * V
return A + center, norm2(center)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment