Created
March 4, 2015 04:44
-
-
Save dhermes/9ce057da49df63345c33 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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