def rotate(figura, x, y, z, fator): deslocamentoX = figura.getDeslocamentoX() deslocamentoY = figura.getDeslocamentoY() sentidoX = figura.getSentidoX() sentidoY = figura.getSentidoY() moveX = figura.getMoveX() moveY = figura.getMoveY() scale = figura.getScale() cos = m.cos(fator) sin = m.sin(fator) Rx = np.array([[1, 0, 0, 0], [0, cos, -sin, 0], [0, sin, cos, 0], [0, 0, 0, 1]]) Ry = np.array([[cos, 0, sin, 0], [0, 1, 0, 0], [-sin, 0, cos, 0], [0, 0, 0, 1]]) Rz = np.array([[cos, -sin, 0, 0], [sin, cos, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) vertices = poligonos.get_vertices(figura) temp = [] arestas = poligonos.get_arestas(figura) for a in vertices: temp.append(a) B = np.array(temp) if (x == 1): C = np.dot(B, Rx) figura = poligonos.Poligono(arestas, figura.centro, poligonos.get_faces(figura)) figura.addVertice(C) figura.addVerticeO(C) elif (y == 1): C = np.dot(B, Ry) figura = poligonos.Poligono(arestas, figura.centro, poligonos.get_faces(figura)) figura.addVertice(C) figura.addVerticeO(C) elif (z == 1): C = np.dot(B, Rz) figura = poligonos.Poligono(arestas, figura.centro, poligonos.get_faces(figura)) figura.addVertice(C) figura.addVerticeO(C) figura = poligonos.setCentro(figura) figura.setDeslocamentoX(deslocamentoX) figura.setDeslocamentoY(deslocamentoY) figura.setSentidoX(sentidoX) figura.setSentidoY(sentidoY) figura.setMoveX(moveX) figura.setMoveY(moveY) figura.setScale(scale) return figura
def translate(figura, x, y, z): deslocamentoX = figura.deslocamentoX() deslocamentoY = figura.deslocamentoY() if (quadrosChave.quadroChaveTransX(figura)): if (figura.getMoveY()): figura.setMoveY(False) figura.setSentidoY(False) else: figura.setMoveY(True) figura.inverteSentidoX() if (quadrosChave.quadroChaveTransY(figura)): figura.inverteSentidoY() T = np.array([[1, 0, 0, x + deslocamentoX], [0, 1, 0, y + deslocamentoY], [0, 0, 1, z], [0, 0, 0, 1]]) vertices = poligonos.get_vertices(figura) temp = [] arestas = poligonos.get_arestas(figura) for a in vertices: temp.append(a) B = np.array(temp) C = [] for i in B: temp = np.dot(T, [[i[0]], [i[1]], [i[2]], [i[3]]]) linha = [] for j in temp: linha.append(j[0]) C.append(linha) fig = poligonos.Poligono(arestas, figura.centro, poligonos.get_faces(figura)) fig.addVertice(C) fig.addVerticeO(C) fig = poligonos.setCentro(fig) fig.setDeslocamentoX(deslocamentoX) fig.setDeslocamentoY(deslocamentoY) fig.setSentidoX(figura.getSentidoX()) fig.setSentidoY(figura.getSentidoY()) fig.setMoveX(figura.getMoveX()) fig.setMoveY(figura.getMoveY()) fig.setScale(figura.getScale()) return fig
def reflect(figura, qx, qy, qz): x = 1 y = 1 z = 1 if (qx == True): y = -1 z = -1 if (qy == True): x = -1 z = -1 if (qz == True): x = -1 y = -1 A = np.array([[x, 0, 0, 0], [0, y, 0, 0], [0, 0, z, 0], [0, 0, 0, 1]]) vertices = poligonos.get_vertices(figura) temp = [] arestas = poligonos.get_arestas(figura) for a in vertices: temp.append(a) B = np.array(temp) C = np.dot(B, A) fig = poligonos.Poligono(arestas, figura.centro, poligonos.get_faces(figura)) fig.addVertice(C) fig.addVerticeO(C) fig = poligonos.setCentro(fig) fig.setDeslocamentoX(figura.getDeslocamentoX()) fig.setDeslocamentoY(figura.getDeslocamentoY()) fig.setSentidoX(figura.getSentidoX()) fig.setSentidoY(figura.getSentidoY()) fig.setMoveX(figura.getMoveX()) fig.setMoveY(figura.getMoveY()) fig.setScale(figura.getScale()) return fig
def scale(figura, fator): if (figura.getScale() != 0): aux = figura.getScale() figura.setScale(0) figura = scale(figura, 1 / aux) EX = EY = EZ = fator A = np.array([[EX, 0, 0, 0], [0, EY, 0, 0], [0, 0, EZ, 0], [0, 0, 0, 1]]) vertices = poligonos.get_vertices(figura) centro = figura.getCentro() vertices = transladaParaOrigem(vertices, True, centro) temp = [] arestas = poligonos.get_arestas(figura) for a in vertices: temp.append(a) B = np.array(temp) C = np.dot(B, A) C = transladaParaOrigem(C, False, centro) fig = poligonos.Poligono(arestas, figura.centro, poligonos.get_faces(figura)) fig.addVertice(C) fig = poligonos.setCentro(fig) fig.setDeslocamentoX(figura.getDeslocamentoX()) fig.setDeslocamentoY(figura.getDeslocamentoY()) fig.setSentidoX(figura.getSentidoX()) fig.setSentidoY(figura.getSentidoY()) fig.setMoveX(figura.getMoveX()) fig.setMoveY(figura.getMoveY()) fig.setScale(fator) return fig
def shearing(figura, x, y, z, matriz): if (matriz == 1): S = np.array([[1, 0, 0, 0], [0, 1, 0, 0], [x, y, 1, 0], [0, 0, 0, 1]]) elif (matriz == 2): S = np.array([[1, 0, 0, 0], [x, 1, z, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) elif (matriz == 3): S = np.array([[1, y, z, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) else: #Caso não digite nada multiplica pela identidade. S = np.array([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) vertices = poligonos.get_vertices(figura) temp = [] arestas = poligonos.get_arestas(figura) for a in vertices: temp.append(a) B = np.array(temp) R = np.dot(B, S) fig = poligonos.Poligono(arestas, figura.centro, poligonos.get_faces(figura)) fig.addVertice(R) fig = poligonos.setCentro(fig) fig.setDeslocamentoX(figura.getDeslocamentoX()) fig.setDeslocamentoY(figura.getDeslocamentoY()) fig.setSentidoX(figura.getSentidoX()) fig.setSentidoY(figura.getSentidoY()) fig.setMoveX(figura.getMoveX()) fig.setMoveY(figura.getMoveY()) fig.setScale(figura.getScale()) return fig
def projetaPoligonoFaces(poligono, janela): faces = poligonos.get_faces(poligono) cos = math.cos(3.14 / 4) sin = math.sin(3.14 / 4) matrizP = np.array([[1, 0, 0, 0], [0, 1, 0, 0], [cos, sin, 0, 0], [0, 0, 0, 1]]) vertices = poligonos.get_vertices(poligono) temp = [] for a in vertices: temp.append(a) temp = np.array(temp) R = np.dot(temp, matrizP) for i in range(len(R)): for j in range(len(R[i])): R[i][j] = R[i][j] / R[i][len(R[i]) - 1] res = [] for i in faces: f = [] for j in i: f.append([R[j][0], R[j][1]]) res.append(f) vetores = [] for i in faces: vet01 = [] vet01.append(vertices[i[0]][0]) vet01.append(vertices[i[0]][1]) vet01.append(vertices[i[0]][2]) vet02 = [] vet02.append(vertices[i[1]][0]) vet02.append(vertices[i[1]][1]) vet02.append(vertices[i[1]][2]) vet03 = [] vet03.append(vertices[i[2]][0]) vet03.append(vertices[i[2]][1]) vet03.append(vertices[i[2]][2]) vet = [] vet.append([vet02[0] - vet01[0], vet02[1] - vet01[1], vet02[2] - vet01[2]]) vet.append([vet03[0] - vet01[0], vet03[1] - vet01[1], vet03[2] - vet01[2]]) vetores.append(vet)# Pega os vetores ignorando a dimensão W for i in range(len(vetores)): vetores[i] = unit_vector(vetores[i])#Transforma os vetores em unitario normal = [] for i in range(len(vetores)): normalTemp = np.cross(vetores[i][0], vetores[i][1])#Calcula a normal das faces normal.append(normalTemp) vetorluz = unit_vector([0, 1, 1])#Vetor que diz a direção da luz angulo = [] for i in range(len(normal)): angulo.append(angle_between(normal[i], vetorluz)) angulo[i] = angulo[i]*180/math.pi # Transforma radianos em graus i = 0 for face in res: cor = [168 - angulo[i], 168 - angulo[i], 168 - angulo[i]] pygame.draw.polygon(janela, cor, face) i += 1