Created
February 6, 2015 09:31
-
-
Save hogart/edcb523f24bb74da617a to your computer and use it in GitHub Desktop.
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
(function () { | |
var deg120 = Math.PI * 2/3; | |
var deg240 = Math.PI * 4/3; | |
var cos120 = Math.cos(deg120); | |
var sin120 = Math.sin(deg120); | |
var cos240 = Math.cos(deg240); | |
var sin240 = Math.sin(deg240); | |
/** | |
* Given center and radius of circumcircle, return points of triangle's vertices | |
* @param {Number} x | |
* @param {Number} y | |
* @param {Number} radius | |
* @return {[[Number]]} | |
*/ | |
function trianglePoints (x, y, radius) { | |
var c = [x, y + radius]; | |
var bx = c[0] * cos120 - c[1] * sin120; | |
var by = c[0] * sin120 + c[1] * cos120; | |
var ax = c[0] * cos240 - c[1] * sin240; | |
var ay = c[0] * sin240 + c[1] * cos240; | |
return [c, [bx, by], [ax, ay]] | |
} | |
return trianglePoints; | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment