public static Poliedro Esfera(int Pasos) { Vertice[] Vertices = new Vertice[(Math.Pow(Pasos, 2)) - Pasos + 2]; Cara[] Caras = new Cara[(Math.Pow(Pasos, 2))]; int cont = 0; int contc = 0; double Radio = 1; for (int i = 0; i <= Pasos - 1; i++) { Caras[i] = new Cara(3); } for (int i = Pasos; i <= (Math.Pow(Pasos, 2)) - Pasos - 1; i++) { Caras[i] = new Cara(4); } for (int i = (Math.Pow(Pasos, 2)) - Pasos; i <= (Math.Pow(Pasos, 2)) - 1; i++) { Caras[i] = new Cara(3); } cont = 1; contc = 0; Vertices[0] = new Vertice(new Punto3D(0, 0, 1)); Vertices[Vertices.GetUpperBound(0)] = new Vertice(new Punto3D(0, 0, -1)); for (double a = 0; a <= Math.PI; a += Math.PI / (Pasos / 1)) { if (a == 0 | a == Math.PI) continue; Radio = Math.Sin(a); for (double b = 0; b <= 2 * Math.PI; b += Math.PI / (Pasos / 2)) { if (b == 2 * Math.PI) continue; Vertices[cont] = new Vertice(new Punto3D(Radio * Math.Cos(b), Radio * Math.Sin(b), Math.Cos(a))); if (cont == Vertices.GetUpperBound(0)) break; // TODO: might not be correct. Was : Exit For cont += 1; } if (cont == (Math.Pow(Pasos, 2)) - 1) break; // TODO: might not be correct. Was : Exit For } cont = 1; for (int i = 0; i <= Pasos - 1; i++) { Caras[i].Vertices[0] = 0; Caras[i].Vertices[1] = (cont + 1 <= Pasos - 0 ? cont + 1 : 1); Caras[i].Vertices[2] = cont; if (cont == Pasos) break; // TODO: might not be correct. Was : Exit For cont += 1; } cont = Vertices.GetUpperBound(0) - Pasos - 1; for (int i = Caras.GetUpperBound(0) - Pasos; i <= Caras.GetUpperBound(0); i++) { Caras[i].Vertices[0] = cont; Caras[i].Vertices[1] = (cont + 1 < Vertices.GetUpperBound(0) - 1 ? cont + 1 : Vertices.GetUpperBound(0) - Pasos - 1); Caras[i].Vertices[2] = Vertices.GetUpperBound(0); if (cont == Vertices.GetUpperBound(0) - 1) break; // TODO: might not be correct. Was : Exit For cont += 1; } for (int i = 1; i <= Pasos - 2; i++) { for (int j = 0; j <= Pasos - 1; j++) { Caras[(i * Pasos) + j].Vertices[0] = ((i - 1) * Pasos) + j + 1; Caras[(i * Pasos) + j].Vertices[1] = (j + 1 <= Pasos - 1 ? ((i - 1) * Pasos) + j + 2 : ((i - 1) * Pasos) + 1); Caras[(i * Pasos) + j].Vertices[2] = (j + 1 <= Pasos - 1 ? ((i) * Pasos) + j + 2 : ((i) * Pasos) + 1); Caras[(i * Pasos) + j].Vertices[3] = ((i) * Pasos) + j + 1; } } return new Poliedro(Vertices, Caras); }
public static Poliedro Malla(int Dimensiones, int NumeroCeldas) { Vertice[] Vertices = null; Cara[] Caras = null; double p = -(Dimensiones / 2); double d = (Dimensiones / NumeroCeldas); int indice = 0; Vertices = new Vertice[(Math.Pow((NumeroCeldas + 1), 2))]; Caras = new Cara[(Math.Pow(NumeroCeldas, 2))]; for (int i = 0; i <= NumeroCeldas; i++) { for (int j = 0; j <= NumeroCeldas; j++) { Vertices[(i * (NumeroCeldas + 1)) + j] = new Vertice(new Punto3D(p + (d * (j)), 0, p + (d * (i)))); } } for (int i = 0; i <= NumeroCeldas - 1; i++) { for (int j = 0; j <= NumeroCeldas - 1; j++) { indice = (i * (NumeroCeldas)) + j; Caras[indice] = new Cara(indice, indice + 1, indice + NumeroCeldas + 2, indice + NumeroCeldas + 1); } } return new Poliedro(Vertices, Caras); }
public static Poliedro Cubo() { Vertice[] Vertices = new Vertice[8]; Cara[] Caras = new Cara[6]; Vertices[0] = new Vertice(new Punto3D(-1, -1, -1)); Vertices[1] = new Vertice(new Punto3D(1, -1, -1)); Vertices[2] = new Vertice(new Punto3D(1, 1, -1)); Vertices[3] = new Vertice(new Punto3D(-1, 1, -1)); Vertices[4] = new Vertice(new Punto3D(-1, -1, 1)); Vertices[5] = new Vertice(new Punto3D(1, -1, 1)); Vertices[6] = new Vertice(new Punto3D(1, 1, 1)); Vertices[7] = new Vertice(new Punto3D(-1, 1, 1)); Caras[0] = new Cara(3, 2, 1, 0); Caras[1] = new Cara(4, 5, 6, 7); Caras[2] = new Cara(7, 6, 2, 3); Caras[3] = new Cara(4, 7, 3, 0); Caras[4] = new Cara(5, 4, 0, 1); Caras[5] = new Cara(6, 5, 1, 2); //For i As Integer = 0 To 5 // Caras(i).RevertirVertices() //Next return new Poliedro(Vertices, Caras); }
public Poliedro(Vertice[] Vertices, Cara[] Caras) { if (Vertices.GetUpperBound(0) >= 3) { if (Caras.GetUpperBound(0) >= 3) { mCaras = Caras; for (int i = 0; i <= mCaras.GetUpperBound(0); i++) { mCaras[i].Color = Color.White; } mVertices = Vertices; mAutoRecalcularCajas = false; AutoReclcNorms = true; RecalcularCentro(); CalcularCarasVertices(); RecalcularDatosCaras(); RecalcularNormalesVertices(); mConstantesShading = new PhongShader(); mVertical = new Vector3D(0, 1, 0); } else { throw new ExcepcionPrimitiva3D("POLIEDRO (NEW): Un poliedro debe tener al menos 4 caras" + Constants.vbNewLine + "Numero de caras=" + Vertices.GetUpperBound(0) + 1); } } else { throw new ExcepcionPrimitiva3D("POLIEDRO (NEW): Un poliedro debe tener al menos 4 vertices" + Constants.vbNewLine + "Numero de vertices=" + Vertices.GetUpperBound(0) + 1); } }
public static Punto3D BaricentroCaraSRC(Cara Cara, Vertice[] Vertices) { return Punto3D.Baricentro(Cara.PuntosSRC[Vertices]); }
public static Plano3D PlanoSRC(Cara Cara, Vertice[] Vertices) { return new Plano3D(Vertices[Cara.Vertices[0]].CoodenadasSRC, Vertices[Cara.Vertices[1]].CoodenadasSRC, Vertices[Cara.Vertices[2]].CoodenadasSRC); }
public static Vector3D VectorNormalSRC(Cara Cara, Vertice[] Vertices) { return (new Vector3D(Vertices[Cara.Vertices[0]].CoodenadasSRC, Vertices[Cara.Vertices[1]].CoodenadasSRC) + new Vector3D(Vertices[Cara.Vertices[0]].CoodenadasSRC, Vertices[Cara.Vertices[2]].CoodenadasSRC)).VectorUnitario; }