Skip to content

Instantly share code, notes, and snippets.

@marmakoide
Last active January 14, 2019 09:52
Show Gist options
  • Save marmakoide/fe662ec88b05f08db5a99db059fa1bc6 to your computer and use it in GitHub Desktop.
Save marmakoide/fe662ec88b05f08db5a99db059fa1bc6 to your computer and use it in GitHub Desktop.
Computes the N-dimension circumsphere of M points, returning its center and its radius, assuming M <= N + 1
import numpy
def get_circumsphere(S):
U = S[1:] - S[0]
B = numpy.sqrt(numpy.sum(U ** 2, axis = 1))
U /= B[:,None]
C = numpy.dot(numpy.linalg.solve(numpy.inner(U, U), .5 * B), U)
return C + S[0], numpy.sqrt(numpy.sum(C ** 2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment