Created
July 30, 2015 08:48
-
-
Save JordanDelcros/cea7b8b231660ebccc6f to your computer and use it in GitHub Desktop.
Find centroid of a triangle with JavaScript
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
// 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); | |
var centerZ = ((vectorA[2] + vectorB[2] + vectorC[2]) / 3); | |
var center = [centerX, centerY, centerZ]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
2D function:
Usage: