public Circunferencia2D(Punto2D P1, Punto2D P2, Punto2D P3) { mCentro = new Punto2D((P1.X + P2.X + P3.X) / 3, (P1.Y + P2.Y + P3.Y) / 3); CuadradoRadio = (Math.Pow((P1.X - mCentro.X), 2)) + (Math.Pow((P1.Y - mCentro.Y), 2)); mRadio = Math.Sqrt(CuadradoRadio); CalculoCoeficientes(); }
public Circunferencia2D(Caja2D Caja) { mCentro = Caja.Centro; mRadio = (Caja.Ancho >= Caja.Alto ? Caja.Ancho / 2 : Caja.Alto / 2); CuadradoRadio = Math.Pow(mRadio, 2); CalculoCoeficientes(); }
public Segmento2D(Punto2D P1, Punto2D P2) { Inicio = P1; Fin = P2; Modulo = Math.Sqrt((Math.Pow((P1.X + P2.X), 2)) + (Math.Pow((P1.Y + P2.Y), 2))); mRecta = new Recta2D(P1, P2); Rectangulo = new Caja2D(P1, new Punto2D(P2.X - P1.X, P2.Y - P1.Y)); }
public Recta2D(params Matriz[] Matrices) { if (Matrices.GetUpperBound(0) == 1) { Punto2D Punto = new Punto2D(Matrices[0]); Punto2D Punto2 = new Punto2D(Matrices[1]); mPunto = Punto; mPuntoMira = Punto2; mVector = new Vector2D(mPunto, mPuntoMira).VectorUnitario; mA = -mVector.Y; mB = mVector.X; mC = -((mA * mPunto.X) + (mB * mPunto.Y)); mPendiente = (mB != 0 ? -(mA / mB) : 0); } else { throw new ExcepcionGeometrica2D("RECTA2D (NEW): La representación matricial de una recta corresponde a un array con dos matrices" + Constants.vbNewLine + "Tamaño del array=" + Matrices.GetUpperBound(0) + 1); } }
public Caja2D(Punto2D Posicion, Punto2D Tamaño) { Pos = new Punto2D(); Size = new Punto2D(); if (Tamaño.X < 0) { Pos.X = Posicion.X + Tamaño.X; Size.X = -Tamaño.X; } else { Pos.X = Posicion.X; Size.X = Tamaño.X; } if (Tamaño.Y < 0) { Pos.Y = Posicion.Y + Tamaño.Y; Size.Y = -Tamaño.Y; } else { Pos.Y = Posicion.Y; Size.Y = Tamaño.Y; } }
public Caja2D(double PosX, double PosY, double Width, double Height) { Pos = new Punto2D(); Size = new Punto2D(); if (Width < 0) { Pos.X = PosX + Width; Size.X = -Width; } else { Pos.X = PosX; Size.X = Width; } if (Height < 0) { Pos.Y = PosY + Height; Size.Y = -Height; } else { Pos.Y = PosY; Size.Y = Height; } }
public bool Pertenece(Punto2D Punto) { return Pertenece(this, Punto); }
public static System.Drawing.Point ToPoint(Punto2D Punto) { int x = 0; int y = 0; if (Punto.X >= int.MinValue) { if (Punto.X <= int.MaxValue) { x = Punto.X; } else { x = int.MaxValue - 1; } } else { x = int.MinValue + 1; } if (Punto.Y >= int.MinValue) { if (Punto.Y <= int.MaxValue) { y = Punto.Y; } else { y = int.MaxValue - 1; } } else { y = int.MinValue + 1; } return new System.Drawing.Point(x, y); }
public static bool Pertenece(Caja2D Caja, Punto2D Punto) { return (Punto.X >= Caja.Left && Punto.X <= Caja.Right && Punto.Y >= Caja.Top && Punto.Y <= Caja.Bottom); }
public static SectorQuadtree[] ObtenerSubSectores(SectorQuadtree Sector) { if (Sector.Nivel < Sector.Niveles - 1) { SectorQuadtree[] Retorno = new SectorQuadtree[4]; Punto2D Tamaño = new Punto2D(Sector.Espacio.Ancho / 2, Sector.Espacio.Alto / 2); Retorno[0] = new SectorQuadtree(Sector, 0, new Caja2D(Sector.Espacio.Posicion, Tamaño)); Retorno[1] = new SectorQuadtree(Sector, 1, new Caja2D(new Punto2D(Sector.Espacio.Left + Tamaño.X, Sector.Espacio.Top), Tamaño)); Retorno[2] = new SectorQuadtree(Sector, 2, new Caja2D(new Punto2D(Sector.Espacio.Left + Tamaño.X, Sector.Espacio.Top + Tamaño.Y), Tamaño)); Retorno[3] = new SectorQuadtree(Sector, 3, new Caja2D(new Punto2D(Sector.Espacio.Left, Sector.Espacio.Top + Tamaño.Y), Tamaño)); return Retorno; } else { throw new ExcepcionGeometrica2D("SECTORQUADTREE (NEW): No se pueden generar subsectores de un sector cuyo nivel es máximo." + Constants.vbNewLine + "Niveles del Quadtree=" + Sector.Niveles.ToString() + Constants.vbNewLine + "Nivel del sector=" + Sector.Niveles); } }
public static Punto2D Baricentro(Punto2D[] Puntos) { double x = 0; double y = 0; x = 0; y = 0; for (int i = 0; i <= Puntos.GetUpperBound(0); i++) { x += Puntos[i].X; y += Puntos[i].Y; } return new Punto2D(x / (Puntos.GetUpperBound(0) + 1), y / (Puntos.GetUpperBound(0) + 1)); }
public static System.Drawing.Point[] ToPoint(Punto2D[] Puntos) { System.Drawing.Point[] Retorno = new System.Drawing.Point[Puntos.GetUpperBound(0) + 1]; for (int i = 0; i <= Puntos.GetUpperBound(0); i++) { Retorno[i] = ToPoint(Puntos[i]); } return Retorno; }
public Recta2D(Punto2D ValPunto, Vector2D ValVector) { mVector = ValVector.VectorUnitario; mPunto = ValPunto; mPuntoMira = new Punto2D(mPunto.X + mVector.X, mPunto.Y + mVector.Y); mA = -mVector.Y; mB = mVector.X; mC = -((mA * mPunto.X) + (mB * mPunto.Y)); mPendiente = (mB != 0 ? -(mA / mB) : 0); }
public double PosicionRelativa(Punto2D Punto) { return (Math.Pow(Punto.X, 2)) + (Math.Pow(Punto.Y, 2)) + (mA * Punto.X) + (mB * Punto.Y) + mC; }
public Circunferencia2D(Punto2D ValCentro, double ValRadio) { mRadio = ValRadio; mCentro = ValCentro; CalculoCoeficientes(); }
public bool ContenidoEnCirculo(Punto2D Punto) { return (Math.Pow(Punto.X, 2)) + (Math.Pow(Punto.Y, 2)) + (mA * Punto.X) + (mB * Punto.Y) + mC < 0; }
public Camara3D() { mTransformacion = new Transformacion3D(); mInversa = new Transformacion3D(); mPosicion = new Punto3D(); mPuntodeMira = new Punto3D(0, 0, 1); mVectorDireccion = new Vector3D(0, 0, 1); mDistancia = 1000; mFrustum = new Caja3D(-50000, -50000, 1000, 100000, 100000, 100000); mResolucionPantalla = new Punto2D(800, 600); mRelacionAspecto = new Punto2D(mResolucionPantalla.X / mFrustum.Ancho, mResolucionPantalla.Y / mFrustum.Largo); mPantalla = new Caja2D(-ResolucionPantalla.X / 2, -ResolucionPantalla.Y / 2, ResolucionPantalla.X, ResolucionPantalla.Y); }
public void EstablecerLargoFrustum(double Largo) { mFrustum = new Caja3D(-(mFrustum.Ancho / 2), -Largo / 2, mDistancia, mFrustum.Ancho, Largo, mFrustum.Alto); mRelacionAspecto = new Punto2D(mResolucionPantalla.X / mFrustum.Ancho, mResolucionPantalla.Y / mFrustum.Largo); if (Modificado != null) { Modificado(this); } }
public PosicionRelativa2D(Punto2D ValInterseccion) { mTipo = TipoPosicionRelativa2D.Secante; mInterseccion = ValInterseccion; }
public double SignoPosicionRelativa(Punto2D Punto) { double Retorno = Math.Sign((mA * Punto.X) + (mB * Punto.Y) + mC); if (mPendiente >= 0) { return Retorno; } else { return -Retorno; } }
public int Pertenece(ref Punto2D Punto) { return Pertenece(ref this, ref Punto); }
public Recta2D(double ValA, double ValB, double ValC) { mA = ValA / (Math.Sqrt((Math.Pow(ValA, 2)) + (Math.Pow(ValB, 2)) + (Math.Pow(ValC, 2)))); mB = ValB / (Math.Sqrt((Math.Pow(ValA, 2)) + (Math.Pow(ValB, 2)) + (Math.Pow(ValC, 2)))); mC = ValC / (Math.Sqrt((Math.Pow(ValA, 2)) + (Math.Pow(ValB, 2)) + (Math.Pow(ValC, 2)))); mVector = new Vector2D(mB, -mA); mPunto = new Punto2D(0, -(mC / mB)); mPuntoMira = new Punto2D(mPunto.X + mVector.X, mPunto.Y + mVector.Y); mPendiente = (mB != 0 ? -(mA / mB) : 0); }
public static int Pertenece(ref SectorQuadtree Sector, ref Punto2D Punto) { if (!Sector.EsHoja) { for (int i = 0; i <= 3; i++) { if (Sector.SubSectores[i].Espacio.Pertenece(Punto)) { return i; } } } else { if (Sector.Espacio.Pertenece(Punto)) { return -1; } else { return -2; } } }
public bool Pertenece(Segmento2D Segmento, Punto2D Punto) { return Rectangulo.Pertenece(Punto) && mRecta.Pertenece(Punto); }
public virtual bool Pertenece(Punto2D Punto) { return (((mA * Punto.X) + (mB * Punto.Y) + mC) == 0); }
public bool Pertenece(Punto2D Punto) { return (Math.Pow(Punto.X, 2)) + (Math.Pow(Punto.Y, 2)) + (mA * Punto.X) + (mB * Punto.Y) + mC == 0; }
public SectorQuadtree Sector(Punto2D Punto) { return Sector(this, Punto); }
public static SectorQuadtree Sector(Quadtree Quadtree, Punto2D Punto) { int Resultado = Quadtree.SectorRaiz.Pertenece(ref Punto); SectorQuadtree S = Quadtree.SectorRaiz; if (Resultado != -2) { if (Resultado == -1) { return S; } else { while (Resultado != -2 && Resultado != -1) { Resultado = S.Pertenece(ref Punto); if (Resultado != -2) { if (Resultado == -1) { return S; } else { S = S.SubSectores[Resultado]; } } else { return S.Padre; } } return S; } } else { throw new ExcepcionGeometrica2D("OCTREE (PERTENECE): El punto especificado no pertenece al espacio dominado por el quadtree." + Constants.vbNewLine + "Punto=" + Punto.ToString() + Constants.vbNewLine + "Espacio=" + Quadtree.Espacio.ToString()); } }
public Recta2D(Punto2D P1, Punto2D P2) { mVector = new Vector2D(P1, P2).VectorUnitario; mPunto = P1; mPuntoMira = P2; mA = -mVector.Y; mB = mVector.X; mC = -((mA * P1.X) + (mB * P1.Y)); mPendiente = (mB != 0 ? -(mA / mB) : 0); }
public static Matriz RepresentacionMatricial(Punto2D Punto) { Matriz Retorno = new Matriz(3, 1); Retorno.EstablecerValoresPorColumna(0, Punto.X, Punto.Y, 1); return Retorno; }