Last active
April 13, 2018 11:55
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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