public Sierpinski(int subdivisions = 1) : base() { int NumTris = (int)Math.Pow(4, subdivisions + 1); VerticesCount = NumTris; ColorDataCount = NumTris; IndiceCount = 3 * NumTris; Tetrahedron twhole = new Tetrahedron( new Vector3(0.0f, 0.0f, 1.0f), // Apex center new Vector3(0.943f, 0.0f, -0.333f), // Base center top new Vector3(-0.471f, 0.816f, -0.333f), // Base left bottom new Vector3(-0.471f, -0.816f, -0.333f)); List<Tetrahedron> allTets = twhole.Divide(subdivisions); int offset = 0; foreach (Tetrahedron t in allTets) { vertices.AddRange(t.GetVertices()); indices.AddRange(t.GetIndices(offset * 4)); colors.AddRange(t.GetColorData()); offset++; } }
public Sierpinski(int subdivisions = 1) : base() { int NumTris = (int)Math.Pow(4, subdivisions + 1); VerticesCount = NumTris; ColorDataCount = NumTris; IndiceCount = 3 * NumTris; Tetrahedron twhole = new Tetrahedron( new Vector3(0.0f, 0.0f, 1.0f), // Apex center new Vector3(0.943f, 0.0f, -0.333f), // Base center top new Vector3(-0.471f, 0.816f, -0.333f), // Base left bottom new Vector3(-0.471f, -0.816f, -0.333f)); List <Tetrahedron> allTets = twhole.Divide(subdivisions); int offset = 0; foreach (Tetrahedron t in allTets) { vertices.AddRange(t.GetVertices()); indices.AddRange(t.GetIndices(offset * 4)); colors.AddRange(t.GetColorData()); offset++; } }
public List <Tetrahedron> Divide(int n = 0) { if (n == 0) { return(new List <Tetrahedron>(new Tetrahedron[] { this })); } else { Vector3 halfa = (PointApex + PointA) / 2.0f; Vector3 halfb = (PointApex + PointB) / 2.0f; Vector3 halfc = (PointApex + PointC) / 2.0f; // Calculate points half way between base points Vector3 halfab = (PointA + PointB) / 2.0f; Vector3 halfbc = (PointB + PointC) / 2.0f; Vector3 halfac = (PointA + PointC) / 2.0f; Tetrahedron t1 = new Tetrahedron(PointApex, halfa, halfb, halfc); Tetrahedron t2 = new Tetrahedron(halfa, PointA, halfab, halfac); Tetrahedron t3 = new Tetrahedron(halfb, halfab, PointB, halfbc); Tetrahedron t4 = new Tetrahedron(halfc, halfac, halfbc, PointC); List <Tetrahedron> output = new List <Tetrahedron>(); output.AddRange(t1.Divide(n - 1)); output.AddRange(t2.Divide(n - 1)); output.AddRange(t3.Divide(n - 1)); output.AddRange(t4.Divide(n - 1)); return(output); } }
public List<Tetrahedron> Divide(int n = 0) { if (n == 0) { return new List<Tetrahedron>(new Tetrahedron[] { this }); } else { Vector3 halfa = (PointApex + PointA) / 2.0f; Vector3 halfb = (PointApex + PointB) / 2.0f; Vector3 halfc = (PointApex + PointC) / 2.0f; // Calculate points half way between base points Vector3 halfab = (PointA + PointB) / 2.0f; Vector3 halfbc = (PointB + PointC) / 2.0f; Vector3 halfac = (PointA + PointC) / 2.0f; Tetrahedron t1 = new Tetrahedron(PointApex, halfa, halfb, halfc); Tetrahedron t2 = new Tetrahedron(halfa, PointA, halfab, halfac); Tetrahedron t3 = new Tetrahedron(halfb, halfab, PointB, halfbc); Tetrahedron t4 = new Tetrahedron(halfc, halfac, halfbc, PointC); List<Tetrahedron> output = new List<Tetrahedron>(); output.AddRange(t1.Divide(n - 1)); output.AddRange(t2.Divide(n - 1)); output.AddRange(t3.Divide(n - 1)); output.AddRange(t4.Divide(n - 1)); return output; } }