public Circunferencia2D(Caja2D Caja)
		{
			mCentro = Caja.Centro;
			mRadio = (Caja.Ancho >= Caja.Alto ? Caja.Ancho / 2 : Caja.Alto / 2);
			CuadradoRadio = Math.Pow(mRadio, 2);
			CalculoCoeficientes();
		}
Beispiel #2
0
		public Quadtree(int Niveles, Caja2D Caja)
		{
			if (Niveles > 1) {
				mNiveles = Niveles;

				mSectorRaiz = new SectorQuadtree(Niveles, Caja);
			} else {
				throw new ExcepcionGeometrica2D("OCTREE (NEW): Un octree debe tener al menos dos niveles:" + Constants.vbNewLine + "Niveles=" + Niveles);
			}
		}
Beispiel #3
0
		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));
		}
Beispiel #4
0
		public void Actualizar()
		{
			Punto2D Bar = Baricentro;
			Punto2D Punto = null;
			double maxX = 0;
			double MaxY = 0;
			double minX = 0;
			double minY = 0;

			if (mRozamientoActivado) {
				if (Math.Abs(mVelocidad.X) - mRozamiento >= 0)
					mVelocidad.X += (-Math.Sign(mVelocidad.X) * mRozamiento);
				else
					mVelocidad.X = 0;
				if (Math.Abs(mVelocidad.Y) - mRozamiento >= 0)
					mVelocidad.Y += (-Math.Sign(mVelocidad.Y) * mRozamiento);
				else
					mVelocidad.Y = 0;
				if (Math.Abs(mVelocidadAngular) - mRozamiento >= 0)
					mVelocidadAngular += (-Math.Sign(mVelocidadAngular) * mRozamiento);
				else
					mVelocidadAngular = 0;

				Movimiento = Transformacion2D.Traslacion(mVelocidad);
				Giro = Transformacion2D.Rotacion(mVelocidadAngular);
			}

			Centro = Transformacion2D.Traslacion(-Bar.X, -Bar.Y);
			VueltaCentro = Transformacion2D.Traslacion(Bar.X, Bar.Y);

			Transformacion = Centro + Giro + VueltaCentro + Movimiento;

			for (int i = 0; i <= base.Segmentos.GetUpperBound(0); i++) {
				Punto = Transformacion * base.Segmentos[i].ExtremoInicial;

				if (i == 0) {
					minX = Punto.X;
					minY = Punto.Y;
					maxX = Punto.X;
					MaxY = Punto.Y;

					base.Segmentos[i].ExtremoInicial = Punto;
				} else {
					if (i < base.Segmentos.GetUpperBound(0)) {
						base.Segmentos[i - 1].ExtremoFinal = Punto;
						base.Segmentos[i].ExtremoInicial = Punto;
					} else {
						base.Segmentos[i - 1].ExtremoFinal = Punto;
						base.Segmentos[i].ExtremoInicial = Punto;
						base.Segmentos[i].ExtremoFinal = base.Segmentos[0].ExtremoInicial;
					}
				}

				if (Punto.X < minX)
					minX = Punto.X;
				if (Punto.X > maxX)
					maxX = Punto.X;
				if (Punto.Y < minY)
					minY = Punto.Y;
				if (Punto.Y > MaxY)
					MaxY = Punto.Y;
			}

			mCaja = new Caja2D(minX, minY, Math.Abs(maxX - minX), Math.Abs(MaxY - minY));

			if (Modificado != null) {
				Modificado(this);
			}
		}
Beispiel #5
0
		public bool Colisionan(Caja2D Caja)
		{
			return Colisionan(this, Caja);
		}
Beispiel #6
0
		public static Caja2D[] SubCajasDiagonales(Caja2D Caja, int PendienteDiagonal, int Nivel)
		{
			Caja2D[] Cajas = null;

			Cajas = new Caja2D[(Math.Pow(2, Nivel))];
			if (PendienteDiagonal >= 0) {
				for (int i = 0; i <= (Math.Pow(2, Nivel)) - 1; i++) {
					Cajas[i] = new Caja2D(new Punto2D(Caja.Posicion.X + i * (Caja.Ancho / (Math.Pow(2, Nivel))), Caja.Posicion.Y + i * (Caja.Alto / (Math.Pow(2, Nivel)))), new Punto2D((Caja.Ancho / (Math.Pow(2, Nivel))), (Caja.Alto / (Math.Pow(2, Nivel)))));
				}
			} else {
				for (int i = 0; i <= (Math.Pow(2, Nivel)) - 1; i++) {
					Cajas[i] = new Caja2D(new Punto2D(Caja.Posicion.X + Caja.Ancho - i * (Caja.Ancho / (Math.Pow(2, Nivel))) - (Caja.Ancho / (Math.Pow(2, Nivel))), Caja.Posicion.Y + i * (Caja.Alto / (Math.Pow(2, Nivel)))), new Punto2D((Caja.Ancho / (Math.Pow(2, Nivel))), (Caja.Alto / (Math.Pow(2, Nivel)))));
				}
			}


			return Cajas;
		}
Beispiel #7
0
		public static Caja2D[] SubCajasDiagonales(Caja2D Caja, int PendienteDiagonal)
		{
			return SubCajasDiagonales(Caja, PendienteDiagonal, 1);
		}
Beispiel #8
0
		public static bool Colisionan(Caja2D C1, Caja2D C2)
		{
			Caja2D R = new Caja2D(C1.Posicion.X - C2.Ancho, C1.Posicion.Y - C2.Alto, C1.Ancho + C2.Ancho, C1.Alto + C2.Alto);

			return Pertenece(R, C2.Posicion);
		}
Beispiel #9
0
		public static Caja2D[] UltimasCajasBSP(Segmento2D S1, Segmento2D S2, int NivelesBSP = 1)
		{
			int Nivel = 1;
			Caja2D[] CajasS1 = null;
			Caja2D[] CajasS2 = null;
			if (NivelesBSP < 1)
				NivelesBSP = 1;
			Caja2D[] Retorno = null;

			CajasS1 = Caja2D.SubCajasDiagonales(S1.Caja, S1.Pendiente);
			CajasS2 = Caja2D.SubCajasDiagonales(S2.Caja, S2.Pendiente);

			while (true) {
				for (int i = 0; i <= 1; i++) {
					for (int j = 0; j <= 1; j++) {
						if (Caja2D.Colisionan(CajasS1[i], CajasS2[j])) {
							if (Nivel < NivelesBSP) {
								CajasS1 = Caja2D.SubCajasDiagonales(CajasS1[i], S1.Pendiente);
								CajasS2 = Caja2D.SubCajasDiagonales(CajasS2[j], S2.Pendiente);
								Nivel += 1;
								continue;
							} else {
								Retorno = new Caja2D[2];

								Retorno[0] = CajasS1[i];
								Retorno[1] = CajasS2[j];

								return Retorno;
							}
						}
					}
				}

				Retorno = new Caja2D[4];

				Retorno[0] = CajasS1[0];
				Retorno[1] = CajasS1[1];
				Retorno[2] = CajasS2[0];
				Retorno[3] = CajasS2[1];

				return Retorno;
			}

			Retorno = new Caja2D[4];

			Retorno[0] = CajasS1[0];
			Retorno[1] = CajasS1[1];
			Retorno[2] = CajasS2[0];
			Retorno[3] = CajasS2[1];

			return Retorno;
		}
		public static int Pertenece(ref SectorQuadtree Sector, ref Caja2D Caja)
		{
			if (!Sector.EsHoja && Caja.Dimensiones < Sector.Espacio.Dimensiones / 2) {
				//LA CAJA PERTENECE A ALGUNO DE LOS HIJOS DEL SECTOR:
				for (int i = 0; i <= 3; i++) {
					if (Sector.SubSectores[i].Espacio.Colisionan(Caja)) {
						return i;
					}
				}
			} else {
				if (Caja.Dimensiones < Sector.Espacio.Dimensiones && Sector.Espacio.Colisionan(Caja)) {
					//LA CAJA PERTENECE AL SECTOR:
					return -1;
				} else {
					//LA CAJA NO PERTENECE AL SECTOR:
					return -2;
				}
			}
		}
Beispiel #11
0
		public static SectorQuadtree Sector(Quadtree Quadtree, Caja2D Caja)
		{
			int Resultado = Quadtree.SectorRaiz.Pertenece(ref Caja);
			SectorQuadtree S = Quadtree.SectorRaiz;

			//PARA ENTENDER EL ALGORITMO, IR A FUNCION PERTENECE DE SECTORQUADTREE.
			if (Resultado != -2) {
				if (Resultado == -1) {
					return Quadtree.SectorRaiz;
				} else {
					do {
						if (Resultado != -2) {
							if (Resultado == -1) {
								return S;
							} else {
								S = S.SubSectores[Resultado];
							}
						} else {
							return S.Padre;
						}
						Resultado = S.Pertenece(ref Caja);
					} while (Resultado != -2 && Resultado != -1);

					return S;
				}
			} else {
				throw new ExcepcionGeometrica2D("OCTREE (PERTENECE): La caja especificada no pertenece al espacio dominado por el quadtree." + Constants.vbNewLine + "Caja=" + Caja.ToString() + Constants.vbNewLine + "Espacio=" + Quadtree.Espacio.ToString());
			}
		}
Beispiel #12
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);
		}
Beispiel #13
0
		private void RecalcCaja()
		{
			mRecta = new Recta2D(Inicio, Fin);
			Rectangulo = new Caja2D(Inicio, new Punto2D(Fin.X - Inicio.X, Fin.Y - Inicio.Y));
			Modulo = Math.Sqrt((Math.Pow((Inicio.X + Fin.X), 2)) + (Math.Pow((Inicio.Y + Fin.Y), 2)));
		}
		public SectorQuadtree(ref SectorQuadtree Padre, int Indice, Caja2D Caja)
		{
			if (Padre.Niveles > 1) {
				if (Nivel >= 0 && Nivel < Padre.Niveles) {
					if (Indice >= 0 && Indice <= 3) {
						mNivel = Padre.Nivel + 1;
						mNiveles = Padre.Niveles;
						mIndice = Indice;
						mEspacio = Caja;
						mPadre = Padre;

						if (mNivel < mNiveles - 1) {
							mSubSectores = ObtenerSubSectores(this);
						}
					} else {
						throw new ExcepcionGeometrica2D("SECTORQUADTREE (NEW): El indice de un sector de Quadtree debe estar comprendido entre 0 y 3." + Constants.vbNewLine + "Indice=" + Indice.ToString());
					}

				} else {
					throw new ExcepcionGeometrica2D("SECTORQUADTREE (NEW): El nivel de un sector de Quadtree debe estar entre 0 y el número de niveles del Quadtree menos uno." + Constants.vbNewLine + "Niveles del Quadtree=" + Niveles.ToString() + Constants.vbNewLine + "Nivel del sector=" + Nivel.ToString());
				}

			} else {
				throw new ExcepcionGeometrica2D("SECTORQUADTREE (NEW): Un Quadtree debe tener al menos dos niveles." + Constants.vbNewLine + "Niveles del Quadtree=" + Niveles.ToString());
			}
		}
Beispiel #15
0
		public SectorQuadtree Sector(Caja2D Caja)
		{
			return Sector(this, Caja);
		}
		public int Pertenece(ref Caja2D Caja)
		{
			return Pertenece(ref this, ref Caja);
		}
Beispiel #17
0
		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);
		}
		//SOLO PARA EL NODO RAIZ:
		public SectorQuadtree(int Niveles, Caja2D Espacio)
		{
			if (Niveles > 1) {
				mNivel = 0;
				mNiveles = Niveles;
				mIndice = 0;
				mEspacio = Espacio;
				mPadre = null;

				if (mNivel < mNiveles - 1) {
					mSubSectores = ObtenerSubSectores(this);
				}
			} else {
				throw new ExcepcionGeometrica2D("SECTORQUADTREE (NEW_RAIZ): Un octree necesita al menos dos niveles." + Constants.vbNewLine + "Niveles=" + Niveles.ToString());
			}
		}
Beispiel #19
0
		public virtual void EstablecerVertices(params Punto2D[] Vertices)
		{
			if (Vertices.GetUpperBound(0) > 1) {
				Segmentos = new Segmento2D[Vertices.GetUpperBound(0) + 1];

				for (int i = 0; i <= Vertices.GetUpperBound(0); i++) {
					if (i < Vertices.GetUpperBound(0)) {
						Segmentos[i] = new Segmento2D(Vertices[i], Vertices[i + 1]);
					} else {
						Segmentos[i] = new Segmento2D(Vertices[i], Vertices[0]);
					}
				}
				mCaja = ObtenerCaja();

				if (Modificado != null) {
					Modificado(this);
				}
			}
		}