Let me point out that what people are discussing here is more properly called the "centroid", a purely geometric concept. the "center or mass" and "center of gravity", which are physics concepts, require a density function. If the density is a constant, then the "center of mass" and "center of gravity" are the same as the "centoid". Yes, the centroid of a triangle is just the point whose coordinates are the average of the corresponding coordinates of the vertices. For a general polygon, it is a little more complicated- you can divide the polygon into triangles, find the centroid of each triangle, the find the weighted average of those, the "weighting" being by the area of the triangles. For more general figures, with curved sides, you will need to integrate.
Same thing in three dimensions. The coordinates of the centroid of a tetrahedron are the average of the corresponding coordinates of the four vertices. Any polyhedron can be divided into tetrahedrons and the centroid is the weighted average of the centroids of the tetrahedron (weighted by their volume) while centroids of figures with curved surfaces require integration.