Created
February 23, 2017 21:40
-
-
Save xyfeng/749d1a9583c9b7498008176e88e43f58 to your computer and use it in GitHub Desktop.
3 points and circle
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
// calcuate center point from given three points | |
// http://paulbourke.net/geometry/circlesphere/ | |
PVector calculateCenter(PVector p1, PVector p2, PVector p3) { | |
float ma = (p2.y - p1.y) / (p2.x - p1.x); | |
float mb = (p3.y - p2.y) / (p3.x - p2.x); | |
float x = (ma * mb * (p1.y - p3.y) + mb * (p1.x + p2.x) - ma * (p2.x + p3.x)) / ( 2 * (mb - ma)); | |
float y = (p1.x - p3.x + ma * (p1.y + p2.y) - mb * (p2.y + p3.y)) / (2 * (ma - mb)); | |
return new PVector(x, y); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment