示例#1
0
        def _collides(x1, y1, x2, y2, x3, y3, x4, y4):
            i = Geometry.intersect_seg(x1, y1, x2, y2, x3, y3, x4, y4)

            if i is not None:
                if y2 == y1:
                    n = 0 + math.pi / 2.0
                else:
                    n = math.atan((x2 - x1) / (y2 - y1)) + math.pi / 2.0

                if y4 == y3:
                    i1 = 0 - n
                else:
                    i1 = math.atan((x4 - x3) / (y4 - y3)) - n

                # i1 = math.pi / 2 - Geometry.angle(x1, y1, x2, y2, x3, y3, x4, y4)

                if self.indice == p.last_indice:
                    n1 = self.indice
                    n2 = p.last_indice
                else:
                    n1 = p.last_indice
                    n2 = self.indice

                sini2 = math.sin(i1) * n1 / n2
                if math.fabs(sini2) <= 1:
                    i2 = math.asin(sini2)
                    # print i2 / math.pi * 360

                    c = math.cos(-i1 + math.pi + i2)
                    s = math.sin(-i1 + math.pi + i2)
                    vx = p.vx * c - p.vy * s
                    vy = p.vx * s + p.vy * c
                    p.vx = vx
                    p.vy = vy

                    print 180 * i1 / math.pi, 180 * i2 / math.pi

                    if not p in self.inside:
                        self.inside[p] = True
                    else:
                        self.inside[p] = not self.inside[p]
                    if not self.inside[p]:
                        p.last_indice = self.indice
                else:
                    # print 'coucou'
                    c = math.cos(-2 * i1)
                    s = math.sin(-2 * i1)
                    vx = p.vx * c - p.vy * s
                    vy = p.vx * s + p.vy * c
                    # p.vx = vx
                    # p.vy = vy

                return True
            return False
示例#2
0
	def collides(self,p):
		#if Geometry.intersec_seg(self,{'x':p}):
		#try:
		#	if Geometry.intersect(self.x1,self.y1,self.x2,self.y2,p.x,p.y,p.old_x,p.old_y):
		#		p.kill()
		#except ZeroDivisionError:
		#	pass
		i = Geometry.intersect_seg(self.x1,self.y1,self.x2,self.y2,p.x,p.y,p.old_x,p.old_y)
		#if i is not None: p.kill()
		#if i is not None: p.engine.rem_part(p)
		if i is not None:
			if self.is_a_barrier:
				p.kill()
			else:
				#print "Mirror intersection!! ", p.id
				# ix,iy = i
				# p.x = ix
				# p.y = iy
				# p.x = p.old_x
				# p.y = p.old_y
				p.x = (i[0]*9+p.old_x)/10.0
				p.y = (i[1]*9+p.old_y)/10.0
				p.vx, p.vy = Geometry.reflect(self.x2-self.x1, self.y2-self.y1, p.vx, p.vy)