Skip to content

Instantly share code, notes, and snippets.

View Vamoss's full-sized avatar

Carlos de Oliveira Junior Vamoss

View GitHub Profile
@JordanDelcros
JordanDelcros / triangle-center.js
Created July 30, 2015 08:48
Find centroid of a triangle with JavaScript
// Very simple way to compute the center (centroid) of a triangle.
// The only things you have to know are the three vectors forming the triangle.
// vector = [x, y, z];
var vectorA = [-1, -3, -2];
var vectorB = [2, 1, 2];
var vectorC = [8, -4, 1];
var centerX = ((vectorA[0] + vectorB[0] + vectorC[0]) / 3);
var centerY = ((vectorA[1] + vectorB[1] + vectorC[1]) / 3);