Пример #1
0
 def test_str_punto(self,x, y, string):
     punto = Punto (x,y)
     self.assertEqual(punto.__str__(), string)
Пример #2
0
 def test_str(self):
     punto = Punto(1, 2)
     self.assertEqual(punto.__str__(), '(1, 2)')
Пример #3
0
	def addVertice_i(self, x, y, i):
		"""Sobreescribe el vertice en la posicion i por el creado con las coordenadas x, y """
		if i >= len(self.vertices) or i<0:
			return False
		v = Punto(x, y)
		print(i)

		if self.cerrado:
			if i == 0:
				a1 = Arista(self.vertices[-1], v)
				a2 = Arista(v, self.vertices[1])
			elif i == len(self.vertices)-1:
				a1 = Arista(self.vertices[i-1], v)
				a2 = Arista(v, self.vertices[0])
			else:
				a1 = Arista(self.vertices[i-1], v)
				a2 = Arista(v, self.vertices[i+1])
			aristas_tmp = self.aristas[:]
			self.aristas[i-1] = a1
			self.aristas[i] = a2
		
			if self.checaInterseccionArista(a1) or self.checaInterseccionArista(a2):
				self.aristas = aristas_tmp
				return False
			else:
				self.vertices[i] = v
				return True
		else:
			aristas_tmp = self.aristas[:]
			if i == 0:
				#a1 = Arista(self.vertices[-1], v)
				a = Arista(v, self.vertices[1])
				self.aristas[i] = a
				if self.checaInterseccionArista(a):
					self.aristas = aristas_tmp
					return False
				else:
					self.vertices[i] = v
					return True

			elif i == len(self.vertices)-1:
				a = Arista(self.vertices[i-1], v)
				self.aristas[-1] = a
				if self.checaInterseccionArista(a):
					self.aristas = aristas_tmp
					return False
				else:
					self.vertices[-1] = v
					return True
			else:
				a1 = Arista(self.vertices[i-1], v)
				a2 = Arista(v, self.vertices[i+1])
			
				self.aristas[i-1] = a1
				self.aristas[i] = a2
		
				if self.checaInterseccionArista(a1) or self.checaInterseccionArista(a2):
					self.aristas = aristas_tmp
					return False
				else:
					self.vertices[i] = v
					return True
Пример #4
0
		Args:
			**args: Un conjunto de argumentos opcionales (excepto superficie):
				color ((int, int, int))
				grosor (int)
				superficie (pygame.Surface): La superficie donde se renderizará.
		"""
        if 'color' in args:
            color = args['color']
        if 'grosor' in args:
            grosor = args['grosor']
        if 'superficie' in args:
            superficie = args['superficie']
        punto_final = self.origen.sumar(self.vector.to_punto())
        pygame.draw.line(superficie, color, self.origen.to_tuple(),
                         punto_final.to_tuple(), grosor)


if __name__ == "__main__":
    from vector import Vector
    from punto import Punto
    pygame.init()
    pantalla = pygame.display.set_mode((600, 400))

    while True:
        pantalla.fill((200, 100, 150))
        vector = Vector(x=10, y=10)
        vector_g = VectorGrafico(Punto(0, 0), vector)
        vector_g.render(pantalla)
        pygame.display.flip()
Пример #5
0
import unittest
from punto import Punto


class TestPunto(unittest.TestCase):
    def test_constructor_vacio(self):
        punto = Punto()
        self.assertDictEqual(punto.__dict__, {'_x': 0, '_y': 0})

    def test_uso_property(self):
        punto = Punto()
        punto.x = 1
        punto.y = 3
        self.assertDictEqual(punto.__dict__, {'_x': 1, '_y': 3})

    def test_constructor_con_valores_iniciales(self):
        punto = Punto(3, 4)
        self.assertDictEqual(punto.__dict__, {'_x': 3, '_y': 4})


if __name__ == '__main__':
    ee = Punto()
Пример #6
0
 def test_str_punto(self):
     punto = Punto(4, 5)
     self.assertEqual(punto.__str__(), "(4, 5")
Пример #7
0
 def calcular_area(self):
     punto_temporal = Punto(self.punto_uno.x, self.punto_dos.y)
     lado_uno = self.punto_uno.calcular_distancia(punto_temporal)
     lado_dos = self.punto_dos.calcular_distancia(punto_temporal)
     self.area = lado_uno * lado_dos / 2
Пример #8
0
 def test_uso_property(self):
     punto = Punto()
     punto.x = 1
     punto.y = 3
     self.assertDictEqual(punto.__dict__, {'_x': 1, '_y': 3})
Пример #9
0
    rospy.loginfo("Enviado el goal...")
    client.wait_for_result()  # esperamos el resultado
    #print('Resultado: %f'%(client.get_result())) # imprime el resultado


# --- main() ---
print("Pulsa 1 para ir al Laboratorio")
print("Pulsa 2 para ir a la Habitacion 321")
print("Pulsa 3 para ir a los Banyos")
print("------------------------------------------")
numero = int(input('Elija una opcion: '))

if numero == 1:
    Punto_Lab = Punto(no="Laboratorio",
                      pos_x=-2.0,
                      pos_y=-4.0,
                      ori_z=0.0,
                      ori_w=1.0)
    mover_robot_a_punto(Punto_Lab)
    print("---------- Moviendo robot ----------")
    condicion_opciones = True

if numero == 2:
    Punto_Hab_321 = Punto(no="Habitacion 321",
                          pos_x=2.5,
                          pos_y=-4.0,
                          ori_z=0.0,
                          ori_w=1.0)
    mover_robot_a_punto(Punto_Hab_321)
    print("---------- Moviendo robot ----------")
    condicion_opciones = True
Пример #10
0
 def calcular_perimetro(self):
     punto_temporal = Punto(self.punto_uno.x, self.punto_dos.y)
     hipo = self.punto_uno.calcular_distancia(self.punto_dos)
     lado_uno = self.punto_uno.calcular_distancia(punto_temporal)
     lado_dos = self.punto_dos.calcular_distancia(punto_temporal)
     self.perimetro = hipo + lado_uno + lado_dos
Пример #11
0
	print("puntos aleatorios")
	for p in puntos:
		print(p.toString())

	print("angulos y puntos")
	angulos = radial.angulos(puntos[0], puntos[1:])
	for a in angulos:
		print(a[0], a[1].toString())

	print("angulos ordernados")
	angulos = radial.ordena_angulos(angulos)
	for a in angulos:
		print(a[0], a[1].toString())
	'''
    #puntos poligono simple
    #puntos = [Punto(1,3), Punto(3,7), Punto(3,1), Punto(1,6), Punto(4,3), Punto(6,4)]
    #puntos poligono ortogonal
    #puntos = [Punto(12,4), Punto(16,4), Punto(16,8), Punto(4,8), Punto(4,4), Punto(8,4), Punto(8,6), Punto(12,6)]
    puntos = [Punto(3, 0), Punto(3, 3), Punto(0, 0), Punto(0, 3), Punto(3, 2)]
    centro = Punto(2, -1)
    print("orden generado:")
    ordenados = radial.ordena(puntos, centro)
    for p in ordenados:
        print(p.toString())

    #print("orden arreglado:")
    #arreglados = radial.arregla_orden(ordenados, centro)
    #for p in arreglados:
    #	print(p.toString())
Пример #12
0
class AreaInteres():
    def __init__(self,
                 tipo,
                 idai=None,
                 idr=None,
                 x=None,
                 y=None,
                 h=None,
                 xant=None,
                 yant=None,
                 dist=None,
                 cantpuntos=None,
                 umbral=0,
                 persistencia=None):
        self.tipo = tipo
        self.persistencia = persistencia
        self.cantpuntos = cantpuntos
        # DECISIONES DINAMICAS
        self.fotosbuenas = 0
        self.numbuenas = 2

        print "estoy en AreaInteres"
        if idai != None:
            self.idai = idai
        else:
            self.idai = persistencia.guardarAInteres(self.tipo, idr)
            self.puntos = []
            #Si es estaca, creamos ademas el anterior
            if self.esEstaca():
                pAnterior = self.generarPunto(xant, yant, x, y, h, dist,
                                              umbral, True, True)
                self.puntos.append(pAnterior)
                self.actual = pAnterior
                if cantpuntos != None and cantpuntos >= 5:
                    pAnterior = self.generarPunto(xant, yant, x, y, h, dist,
                                                  umbral, True, False)
                    self.puntos.append(pAnterior)

            print "antes de guardar el punto"
            #Para cualquier caso siempre creamos un punto.
            self.exacto = Punto(x, y, h, self, None, persistencia, True)
            self.puntos.append(self.exacto)

            if not self.esEstaca():
                self.actual = self.exacto

    def esEstaca(self):
        return self.tipo == 0

    def esReferencia(self):
        return self.tipo == 2

    def obtenerPunto(self, idp):
        i = 0
        punto = None
        while (i < len(self.puntos)) and not self.puntos[i].sosVos(idp):
            i += 1
        if (i < len(self.puntos)):
            punto = self.puntos[i]
        return punto

    def setPuntos(self, puntos):
        self.puntos = puntos
        self.actual = puntos[0]
        self.exacto = self.actual
        self.cantpuntos = len(self.puntos)
        if self.esEstaca():
            #Cambiado el algoritmos ahora generamos 4 puntos
            if self.cantpuntos >= 5:
                self.exacto = puntos[2]
            else:
                #con 3 o 4 puntos
                self.exacto = puntos[1]
        pass

    def getCantPuntos(self):
        return self.cantpuntos

    def calcularm(self, x0, y0, x1, y1):
        return (y1 - y0) / (x1 - x0)

    def encontrarPuntoRecta(self, m, d):
        return d / sqrt(1 + (m**2))

    def getId(self):
        return self.idai

    def getX(self):
        return self.exacto.getX()

    def getY(self):
        return self.exacto.getY()

    #DECISIONES DINAMICAS
    def calificar(self, regiones, score):
        if regiones >= 1:
            self.fotosbuenas += 1
        return self.fotosbuenas >= self.numbuenas

    def saltarPuntos(self, idp):
        if self.fotosbuenas < self.numbuenas:
            return 0
        else:
            posicionpunto = 0
            for i in range(len(self.puntos)):
                if self.puntos[i].getId() == idp:
                    posicionpunto = i + 1
                    break
            #Reiniciar el contador par la otra mision
            self.fotosbuenas = 0
            #print str(self.cantpuntos-posicionpunto)
            return self.cantpuntos - posicionpunto + 1

    def generarPuntoSig(self, xsig, ysig, dist, umbral):
        #Si es estaca, creamos ademas el siguiente
        e = self.exacto
        if self.esEstaca():
            if self.cantpuntos != None and self.cantpuntos >= 4:
                pSiguiente = self.generarPunto(e.getX(), e.getY(), xsig, ysig,
                                               e.getH(), dist, umbral, False,
                                               True)
                self.puntos.append(pSiguiente)
            pSiguiente = self.generarPunto(e.getX(), e.getY(), xsig, ysig,
                                           e.getH(), dist, umbral, False,
                                           False)
            self.puntos.append(pSiguiente)
            #self.ultidp+=1

    def generarPunto(self, xant, yant, x, y, h, dist, umbral, esAnterior,
                     esPrimero):
        x0 = 0
        y0 = 0
        x1 = x - xant
        y1 = y - yant
        #print str(xant)+str(yant)+","+str(x)+str(y)

        if (esAnterior):
            #Ajustes del umbral
            if esPrimero:
                dist = dist - umbral
            else:
                dist = dist + umbral
        else:
            # Ajustes del umbral
            dist = dist + umbral
        ##El incremento por defecto
        inc = dist

        #print "inc antes:" + str(inc)

        ##si y costante = recta vertical
        if (y0 != y1) and (x0 != x1):
            m = self.calcularm(x0, y0, x1, y1)
            inc = self.encontrarPuntoRecta(m, dist)
        ##Si no es una recta con x constante, por defecto va a cambiar x
        varCambiar = x
        varRefAnt = xant
        ##Si es recta con x constatne entonces cambiar y
        if (x0 == x1):
            varCambiar = y
            varRefAnt = yant

        #print "inc antes:"+str(inc)
        if (esAnterior):
            #Ajustes del umbral
            #	if esPrimero:
            #		inc=inc-umbral
            #	else:
            #		inc = inc + umbral

            #CAMBIO PARA VER DE OBTENER FOTOS EN DOS PUNTOS MAS
            if ((varCambiar > varRefAnt)
                    and esPrimero) or (not (varCambiar > varRefAnt)
                                       and not esPrimero):
                varF = varCambiar - inc
            else:
                varF = varCambiar + inc

        else:
            # Ajustes del umbral
            #inc = inc + umbral

            # CAMBIO PARA VER DE OBTENER FOTOS EN DOS PUNTOS MAS
            if ((varCambiar > varRefAnt)
                    and not esPrimero) or (not (varCambiar > varRefAnt)
                                           and esPrimero):
                varF = varRefAnt + inc
            else:
                varF = varRefAnt - inc

        #print "umbral" + str(umbral) + "-anterior:" + str(esAnterior) + "-primero" + str(esPrimero) + "-varF" + str(varF)
        #print "inc despues:" + str(inc)
        if (x0 == x1):
            yf = varF
            xf = x
        elif (y0 == y1):
            xf = varF
            yf = y
        else:
            xf = varF
            yf = m * (xf - xant) + yant
        return Punto(xf, yf, h, self, None, self.persistencia)

    def getDataPuntos(self):
        resDat = [{
            "id": self.idai,
            "tipo": self.tipo,
            "x": self.exacto.x,
            "y": self.exacto.y,
            "h": self.exacto.h
        }]
        #for p in self.puntos:
        #	auxData=p.getDataPuntos()
        #	resDat.append(auxData)
        #resObj.append(aux["obj"])
        return [resDat, self.puntos]

    def ver(self):
        salida = str(self.idai) + "-" + str(self.tipo) + "\npuntos:"
        for ps in self.puntos:
            salida += ps.ver()
        return salida
Пример #13
0
    def generarPunto(self, xant, yant, x, y, h, dist, umbral, esAnterior,
                     esPrimero):
        x0 = 0
        y0 = 0
        x1 = x - xant
        y1 = y - yant
        #print str(xant)+str(yant)+","+str(x)+str(y)

        if (esAnterior):
            #Ajustes del umbral
            if esPrimero:
                dist = dist - umbral
            else:
                dist = dist + umbral
        else:
            # Ajustes del umbral
            dist = dist + umbral
        ##El incremento por defecto
        inc = dist

        #print "inc antes:" + str(inc)

        ##si y costante = recta vertical
        if (y0 != y1) and (x0 != x1):
            m = self.calcularm(x0, y0, x1, y1)
            inc = self.encontrarPuntoRecta(m, dist)
        ##Si no es una recta con x constante, por defecto va a cambiar x
        varCambiar = x
        varRefAnt = xant
        ##Si es recta con x constatne entonces cambiar y
        if (x0 == x1):
            varCambiar = y
            varRefAnt = yant

        #print "inc antes:"+str(inc)
        if (esAnterior):
            #Ajustes del umbral
            #	if esPrimero:
            #		inc=inc-umbral
            #	else:
            #		inc = inc + umbral

            #CAMBIO PARA VER DE OBTENER FOTOS EN DOS PUNTOS MAS
            if ((varCambiar > varRefAnt)
                    and esPrimero) or (not (varCambiar > varRefAnt)
                                       and not esPrimero):
                varF = varCambiar - inc
            else:
                varF = varCambiar + inc

        else:
            # Ajustes del umbral
            #inc = inc + umbral

            # CAMBIO PARA VER DE OBTENER FOTOS EN DOS PUNTOS MAS
            if ((varCambiar > varRefAnt)
                    and not esPrimero) or (not (varCambiar > varRefAnt)
                                           and esPrimero):
                varF = varRefAnt + inc
            else:
                varF = varRefAnt - inc

        #print "umbral" + str(umbral) + "-anterior:" + str(esAnterior) + "-primero" + str(esPrimero) + "-varF" + str(varF)
        #print "inc despues:" + str(inc)
        if (x0 == x1):
            yf = varF
            xf = x
        elif (y0 == y1):
            xf = varF
            yf = y
        else:
            xf = varF
            yf = m * (xf - xant) + yant
        return Punto(xf, yf, h, self, None, self.persistencia)
Пример #14
0
 def test_contructor_con_valores_iniciales(self):
     punto = Punto(3, 4)
     self.assertDictEqual(punto.__dict__, {'_x': 3, '_y': 4})
Пример #15
0
 def test_x_negativo(self):
     with self.assertRaises(ValueError):
         Punto(-1, 2)
Пример #16
0
 def test_contructor_vacio(self):
     punto = Punto()
     self.assertDictEqual(punto.__dict__, {'_x': 0, '_y': 0})
Пример #17
0
 def test_x_negativo(self):
     x = -1 * random()
     print(x)
     with self.assertRaises(ValueError):
         Punto(x, 3)
Пример #18
0
from punto import Punto
from triangolo import Triangolo

b = Punto(3.0, 5.0)
a = Punto(2.4, 9.1)
c = Punto(1.1, 4.3)

t = Triangolo(a, b, c)

print "x:", b.get_x(), "y:", b.get_y(), t.get_punto_a

    print('El AREA del rectangulo es: ', str(areass))


stop = False
while stop == False:
    print('\n')
    print(
        '''1.-Ingresar punto X,Y \n2.-Ingresar punto A,B  \n3.-HACER OPERACIONES
        ''')
    opcioninicial = input()
    if '1' in opcioninicial:
        print('Valor X: ')
        x = int(input())
        print('Valor Y: ')
        y = int(input())
        x_y = Punto(x=x, y=y)

    elif '2' in opcioninicial:
        print('Valor A: ')
        a = int(input())
        print('Valor B: ')
        b = int(input())

    if '3' in opcioninicial:
        rectangulo = Rectangulo(x=x, y=y)
        print('PUNTOS')
        print('(X,Y) :', '(', x, ',', y, ')')
        print('(A,B) :', '(', a, ',', b, ')')

        stop = False
        while stop == False: