分形之谢尔宾斯基(Sierpinski)四面体
前面讲了谢尔宾斯基三角形,这一节的将对二维三角形扩展到三维,变成四面体.即将一个正四面体不停地拆分,每个正四面体可以拆分成四个小号的正四面体.由二维转变到三维实现起来麻烦了许多。三维的谢尔宾斯基四面体看上去比谢尔宾斯基三角形更像坟冢。
核心代码:
static void SierpinskiTetrahedron(const Vector3* pSrc, Vector3* pDest) { Vector3 v01 = (pSrc[0] + pSrc[1])*0.5f; Vector3 v02 = (pSrc[0] + pSrc[2])*0.5f; Vector3 v03 = (pSrc[0] + pSrc[3])*0.5f; Vector3 v12 = (pSrc[1] + pSrc[2])*0.5f; Vector3 v13 = (pSrc[1] + pSrc[3])*0.5f; Vector3 v23 = (pSrc[2] + pSrc[3])*0.5f; pDest[0] = pSrc[0]; pDest[1] = v01; pDest[2] = v02; pDest[3] = v03; pDest[4] = pSrc[1]; pDest[5] = v01; pDest[6] = v12; pDest[7] = v13; pDest[8] = pSrc[2]; pDest[9] = v02; pDest[10] = v12; pDest[11] = v23; pDest[12] = pSrc[3]; pDest[13] = v03; pDest[14] = v13; pDest[15] = v23; }