Example #1
0
		public static Punto2D Interseccion(Segmento2D S1, Segmento2D S2)
		{
			try {
				Punto2D Pi = Recta2D.Interseccion(S1.Recta, S2.Recta);

				return Pi;
			} catch (ExcepcionGeometrica2D ex) {
				return null;
			}
		}
Example #2
0
		public bool Pertenece(Segmento2D Segmento)
		{
			return (Colisionan(Segmento.Caja) && Pertenece(Segmento.Recta));
		}
Example #3
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;
		}
Example #4
0
		public static bool Colisionan(Segmento2D S1, Segmento2D S2, int Niveles, bool BSP = false)
		{
			Caja2D[] CajasS1 = null;
			Caja2D[] CajasS2 = null;
			if (BSP) {
				int Nivel = 1;
				if (Niveles < 1)
					Niveles = 1;

				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 < Niveles) {
									CajasS1 = Caja2D.SubCajasDiagonales(CajasS1[i], S1.Pendiente);
									CajasS2 = Caja2D.SubCajasDiagonales(CajasS2[j], S2.Pendiente);
									Nivel += 1;
									continue;
								} else {
									return true;
								}
							} else {
								if (Nivel == Niveles && Circunferencia2D.Colisionan(new Circunferencia2D(CajasS1[i]), new Circunferencia2D(CajasS2[j]))) {
									return true;
								}
							}
						}
					}

					return false;
				}
				return false;
			} else {
				CajasS1 = Caja2D.SubCajasDiagonales(S1.Caja, S1.Pendiente, Niveles);
				CajasS2 = Caja2D.SubCajasDiagonales(S2.Caja, S2.Pendiente, Niveles);

				for (int i = 0; i <= CajasS1.GetUpperBound(0); i++) {
					for (int j = 0; j <= CajasS2.GetUpperBound(0); j++) {
						if (Caja2D.Colisionan(CajasS1[i], CajasS2[j])) {
							return true;
						}
					}
				}

				return false;
			}

		}
Example #5
0
		public bool Pertenece(Segmento2D Segmento, Punto2D Punto)
		{
			return Rectangulo.Pertenece(Punto) && mRecta.Pertenece(Punto);
		}
Example #6
0
		public Poligono2D(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]);
					}
				}

				mColor = System.Drawing.Color.White;
			}
		}
Example #7
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);
				}
			}
		}