public Segmento3D(Punto3D P1, Punto3D P2) { mExtremoInicial = P1; mExtremoFinal = P2; mLongitud = Math.Sqrt((Math.Pow((P1.X + P2.X), 2)) + (Math.Pow((P1.Y + P2.Y), 2))); mRecta = new Recta3D(P1, P2); mCaja = new Caja3D(P1, new Vector3D(P2.X - P1.X, P2.Y - P1.Y, P2.Z - P1.Z)); }
public SectorOctree[] Sectores(Recta3D Recta) { return Sectores(this, Recta); }
public static Punto3D Proyeccion(Punto3D Punto, Recta3D Recta) { int Landa = 0; double Vx = 0; double Vy = 0; double Vz = 0; double VVx = 0; double VVy = 0; double VVz = 0; double Qx = 0; double Qy = 0; double Qz = 0; double x = 0; double y = 0; double z = 0; Vx = Recta.VectorDirector.X; Vy = Recta.VectorDirector.Y; Vz = Recta.VectorDirector.Z; VVx = Vx * Vx; VVy = Vy * Vy; VVz = Vz * Vz; Qx = Recta.PuntoInicial.X; Qy = Recta.PuntoInicial.Y; Qz = Recta.PuntoInicial.Z; x = Punto.X; y = Punto.Y; z = Punto.Z; Landa = ((Vx * (x - Qx)) + (Vy * (y - Qy)) + (Vz * (z - Qz))) / (VVx + VVy + VVz); return Recta.ObtenerPuntoParametrico(Landa); }
public static double Distancia(Recta3D R1, Recta3D R2) { switch (PosicionRelativa(R1, R2).Tipo) { case TipoPosicionRelativa3D.Coincidente: return 0; case TipoPosicionRelativa3D.Secante: return 0; case TipoPosicionRelativa3D.Paralelo: return Distancia(R1, R2.ObtenerPuntoParametrico(0)); case TipoPosicionRelativa3D.Cruce: return Math.Abs(Vector3D.ProductoMixto(R1.VectorDirector, R2.VectorDirector, new Vector3D(R1.ObtenerPuntoParametrico(0), R2.ObtenerPuntoParametrico(0)))) / (R1.VectorDirector + R2.VectorDirector).Modulo; } }
public static double Distancia(Recta3D Recta, Plano3D Plano) { if (Recta.VectorDirector * Plano.VectorNormal == 0) { return Distancia(Recta, Plano.ObtenerPunto(0, 0)); } else { return 0; } }
public static int Pertenece(ref SectorOctreeGrafico Sector, ref Recta3D Recta) { if (!Sector.EsHoja) { for (int i = 0; i <= 7; i++) { if (Sector.Hijos[i].Espacio.Pertenece(Recta)) { return i; } } } else { if (Sector.Espacio.Pertenece(Recta)) { return -1; } else { return -2; } } }
public bool Pertenece(ref Recta3D Recta) { return Pertenece(ref this, Recta); }
public static void InterseccionRecta(Recta3D Recta, SectorOctree Sector, ref List<SectorOctree> ListaRetorno) { if (!Sector.EsHoja) { foreach (SectorOctree Hijo in Sector.Hijos) { if (Hijo.Pertenece(ref Recta)) { InterseccionRecta(Recta, Hijo, ref ListaRetorno); } } } else { if (Sector.Pertenece(ref Recta)) ListaRetorno.Add(Sector); } }
private void RecalcularDatos() { mRecta = new Recta3D(mExtremoInicial, mExtremoFinal); mCaja = new Caja3D(mExtremoInicial, new Vector3D(mExtremoFinal.X - mExtremoInicial.X, mExtremoFinal.Y - mExtremoInicial.Y, mExtremoFinal.Z - mExtremoInicial.Z)); mLongitud = Math.Sqrt((Math.Pow((mExtremoInicial.X + mExtremoFinal.X), 2)) + (Math.Pow((mExtremoInicial.Y + mExtremoFinal.Y), 2))); }
public bool Pertenece(Recta3D Recta) { return Pertenece(this, Recta); }
public static Punto3D Interseccion(Plano3D Plano, Recta3D Recta) { SistemaEcuaciones sis = null; if (Plano.VectorNormal * Recta.VectorDirector != 0) { sis = new SistemaEcuaciones(Plano.ObtenerEcuacion(), Recta.PrimerPlano.ObtenerEcuacion(), Recta.SegundoPlano.ObtenerEcuacion()); if (sis.Solucion.TipoSolucion == TipoSolucionSistema.SistemaCompatibleDeterminado) { return new Punto3D(sis.Solucion.ValorSolucion[0], sis.Solucion.ValorSolucion[1], sis.Solucion.ValorSolucion[2]); } else { if (sis.Solucion.TipoSolucion == TipoSolucionSistema.SistemaCompatibleIndeterminado) { return Plano.ObtenerPunto(0, 0); } else { throw new ExcepcionGeometrica3D("PLANO3D (INTERSECCION): No se ha podido calcular la interseccion. Es posible que los datos de los planos sean erroneos, o que el cálculo del sistema halla fallado." + Constants.vbNewLine + "Recta=" + Recta.ToString() + Constants.vbNewLine + "Plano: " + Plano.ToString() + Constants.vbNewLine + "Primer plano: " + Recta.PrimerPlano.ToString() + Constants.vbNewLine + "Seundo plano: " + Recta.SegundoPlano.ToString() + Constants.vbNewLine + "Primera ecuación del sistema: " + Plano.ObtenerEcuacion().ToString() + Constants.vbNewLine + "Segunda ecuación del sistema: " + Recta.PrimerPlano.ObtenerEcuacion().ToString() + Constants.vbNewLine + "Tercera ecuación del sistema: " + Recta.SegundoPlano.ObtenerEcuacion().ToString() + Constants.vbNewLine + "Solución obtenida: " + sis.Solucion.ToString()); } } } else { if (Recta3D.Distancia(Recta, Plano) == 0) { return Recta.PuntoInicial; } else { throw new ExcepcionGeometrica3D("PLANO3D (INTERSECCION): La recta y el plano son paralelos" + Constants.vbNewLine + "Recta: " + Recta.ToString() + Constants.vbNewLine + "Plano: " + Plano.ToString()); } } }
public static Punto3D PuntoCorteRecta(Caja3D Caja, Recta3D Recta) { if (Recta.VectorDirector.X == 0) { if (Recta.VectorDirector.Y == 0) { return Recta.ObtenerPunto(Caja.Centro.Z, EnumEjes.EjeZ); } else { return Recta.ObtenerPunto(Caja.Centro.Y, EnumEjes.EjeY); } } else { return Recta.ObtenerPunto(Caja.Centro.X, EnumEjes.EjeX); } }
public static bool Pertenece(Caja3D Caja, Recta3D Recta) { double PosicionA = Recta.PrimerPlano.SignoPosicionRelativa(Caja.Vertices[0]); double PosicionB = 0; bool PlanoA = false; if (PosicionA == Recta.PrimerPlano.SignoPosicionRelativa(Caja.Vertices[1])) { if (PosicionA == Recta.PrimerPlano.SignoPosicionRelativa(Caja.Vertices[2])) { if (PosicionA == Recta.PrimerPlano.SignoPosicionRelativa(Caja.Vertices[3])) { if (PosicionA == Recta.PrimerPlano.SignoPosicionRelativa(Caja.Vertices[4])) { if (PosicionA == Recta.PrimerPlano.SignoPosicionRelativa(Caja.Vertices[5])) { if (PosicionA == Recta.PrimerPlano.SignoPosicionRelativa(Caja.Vertices[6])) { if (PosicionA == Recta.PrimerPlano.SignoPosicionRelativa(Caja.Vertices[7])) { return false; } else { PlanoA = true; } } else { PlanoA = true; } } else { PlanoA = true; } } else { PlanoA = true; } } else { PlanoA = true; } } else { PlanoA = true; } } else { PlanoA = true; } if (PlanoA) { PosicionB = Recta.SegundoPlano.SignoPosicionRelativa(Caja.Vertices[0]); if (PosicionB == Recta.SegundoPlano.SignoPosicionRelativa(Caja.Vertices[1])) { if (PosicionB == Recta.SegundoPlano.SignoPosicionRelativa(Caja.Vertices[2])) { if (PosicionB == Recta.SegundoPlano.SignoPosicionRelativa(Caja.Vertices[3])) { if (PosicionB == Recta.SegundoPlano.SignoPosicionRelativa(Caja.Vertices[4])) { if (PosicionB == Recta.SegundoPlano.SignoPosicionRelativa(Caja.Vertices[5])) { if (PosicionB == Recta.SegundoPlano.SignoPosicionRelativa(Caja.Vertices[6])) { if (PosicionB == Recta.SegundoPlano.SignoPosicionRelativa(Caja.Vertices[7])) { return false; } else { return true; } } else { return true; } } else { return true; } } else { return true; } } else { return true; } } else { return true; } } else { return true; } } else { return false; } }
public void RotarSobreSUR(Recta3D Eje, float Rotacion) { mTransformacion += new Rotacion(Rotacion, Eje); RecalcularDatos(); if (Modificado != null) { Modificado(this); } }
public static SectorOctree Sector(Octree Octree, Recta3D Recta) { int Resultado = Octree.SectorRaiz.Pertenece(ref Recta); SectorOctree S = Octree.SectorRaiz; if (Resultado != -2) { if (Resultado == -1) { return S; } else { while (Resultado != -2 && Resultado != -1) { Resultado = S.Pertenece(ref Recta); if (Resultado != -2) { if (Resultado == -1) { return S; } else { S = S.Hijos[Resultado]; } } else { return S.Padre; } } return S; } } else { throw new ExcepcionGeometrica3D("OCTREE (PERTENECE): La recta especificada no pertenece al espacio dominado por el quadtree." + Constants.vbNewLine + "Punto=" + Recta.ToString() + Constants.vbNewLine + "Espacio=" + Octree.Espacio.ToString()); } }
public static Matriz[] RepresentacionMatricial(Recta3D Recta) { Matriz[] Retorno = new Matriz[2]; Retorno[0] = Recta.PuntoInicial.Matriz; Retorno[1] = Recta.PuntoMira.Matriz; return Retorno; }
public static SectorOctree[] Sectores(Octree Octree, Recta3D Recta) { SectorOctree S = Octree.SectorRaiz; List<SectorOctree> Retorno = new List<SectorOctree>(); if (Octree.SectorRaiz.Pertenece(ref Recta)) { InterseccionRecta(Recta, S, ref Retorno); return Retorno.ToArray(); } else { throw new ExcepcionGeometrica3D("OCTREE (PERTENECE): La recta especificado no pertenece al espacio dominado por el quadtree." + Constants.vbNewLine + "Recta=" + Recta.ToString() + Constants.vbNewLine + "Espacio=" + Octree.Espacio.ToString()); } }
public static PosicionRelativa3D PosicionRelativa(Recta3D R1, Recta3D R2) { SistemaEcuaciones Sistema = new SistemaEcuaciones(new Ecuacion(R1.VectorDirector.X, R2.VectorDirector.X, R2.PuntoInicial.X - R1.PuntoInicial.Y), new Ecuacion(R1.VectorDirector.Y, R2.VectorDirector.Y, R2.PuntoInicial.Y - R1.PuntoInicial.Y), new Ecuacion(R1.VectorDirector.Z, R2.VectorDirector.Z, R2.PuntoInicial.Z - R1.PuntoInicial.Z)); switch (Sistema.Solucion.TipoSolucion) { case TipoSolucionSistema.SistemaCompatibleDeterminado: return new PosicionRelativa3D(new Punto3D(Sistema.Solucion.ValorSolucion[0], Sistema.Solucion.ValorSolucion[1], Sistema.Solucion.ValorSolucion[2])); case TipoSolucionSistema.SistemaCompatibleIndeterminado: return new PosicionRelativa3D(TipoPosicionRelativa3D.Coincidente); case TipoSolucionSistema.SistemaIncompatible: if (Sistema.RangoMatrizPrincipal == 1) { return new PosicionRelativa3D(TipoPosicionRelativa3D.Paralelo); } else { return new PosicionRelativa3D(TipoPosicionRelativa3D.Cruce); } break; } }
public SectorOctree Sector(Recta3D Recta) { return Sector(this, Recta); }
public static double Distancia(Recta3D Recta, Punto3D Punto) { return (new Vector3D(Recta.ObtenerPuntoParametrico(0), Punto) + Recta.VectorDirector).Modulo; }
public static bool Pertenece(ref SectorOctree Sector, ref Recta3D Recta) { return Sector.Espacio.Pertenece(Recta); }
public int Pertenece(ref Recta3D Recta) { return Pertenece(ref this, ref Recta); }