예제 #1
0
	def tryTrans(self, p0, p2, sens):
		nbp = self.fig.nbp
		virtual_fig = Shape(nbp, [(0,0) for i in range(nbp)])

		p1 = self.fig.shape.at(1)

		#on determine le vecteur de translation a partir des coord du centre et du milieu du trait avant du carre
		x0 = (abs(p0.x() - p2.x())/2 + min((p0.x(), p2.x())))
		y0 = (abs(p0.y() - p2.y())/2 + min((p0.y(), p2.y())))

		x1 = abs(p0.x() - p1.x())/2 + min((p0.x(), p1.x()))
		y1 = (abs(p0.y() - p1.y())/2 + min((p0.y(), p1.y())))

		norme = np.sqrt((x1-x0)**2 + (y1-y0)**2)
		v_t = (sens*(x1-x0)*self.pas/norme, sens*(y1-y0)*self.pas/norme)
		Trans = np.array([[1,0,v_t[0]],[0,1,v_t[1]]])#matrice de translation

		for i in range(nbp):
			point = self.fig.shape.at(i)
			pt = np.array([[point.x()],[point.y()],[1]])
			new_point = np.dot(Trans, pt)

			virtual_fig.shape.replace(i, QPointF(new_point[0], new_point[1]))

		if collisions.check_collisions(virtual_fig, self.ofig, self.geometry()):
			virtual_fig.shape.swap(self.fig.shape)
예제 #2
0
	def tryRotate(self, p0, p2, theta): # p0, p2, theta
		nbp = self.fig.nbp
		virtual_fig = Shape(nbp, [(0,0) for i in range(nbp)])

		#recuperer les coord du centre de rotation à partir du milieu de la diagonale plus la position du carré
		x0 = (abs(p0.x() - p2.x())/2 + min((p0.x(), p2.x())))
		y0 = (abs(p0.y() - p2.y())/2 + min((p0.y(), p2.y())))

		#definir la matrice de rotation
		Rot = np.array([[np.cos(theta),-np.sin(theta)], [np.sin(theta), np.cos(theta)]])

		#appliquer la rotation a l'ensemble des points
		for i in range(nbp):
			point = self.fig.shape.at(i)
			pt = np.array([[point.x()-x0],[point.y()-y0]])
			new_point = np.dot(Rot, pt)

			#mettre a jour les points
			virtual_fig.shape.replace(i, QPointF(new_point[0]+x0, new_point[1]+y0))

		if collisions.check_collisions(virtual_fig, self.ofig, self.geometry()):
			virtual_fig.shape.swap(self.fig.shape)