Skip to content

Instantly share code, notes, and snippets.

@hogart
Created February 6, 2015 09:31
Show Gist options
  • Save hogart/edcb523f24bb74da617a to your computer and use it in GitHub Desktop.
Save hogart/edcb523f24bb74da617a to your computer and use it in GitHub Desktop.
(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