Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: cp1252 -*-
- #Xavier Sánchez Díaz 1540717
- #Operaciones con vectores como objetos
- class Vector:
- def __init__(self, x, y, z):
- self.i = x
- self.j = y
- self.k = z
- def producto_cruz(vector1, vector2):
- x = vector1.j * vector2.k - vector1.k * vector2.j
- y = vector1.i * vector2.k - vector1.k * vector2.i
- z = vector1.i * vector2.j - vector1.j * vector2.i
- return (x, -1* y, z)
- def producto_punto(vector1, vector2):
- return vector1.i * vector2.i + vector1.j * vector2.j + vector1.k * vector2.k
- def suma (vector1, vector2):
- return vector1.i + vector2.i, vector1.j + vector2.j, vector1.k + vector2.k
- def resta (vector1, vector2):
- return vector1.i - vector2.i, vector1.j - vector2.j, vector1.k - vector2.k
- def imprime_vector(vector):
- return vector.i, vector.j, vector.k
- v1 = Vector(0,0,0)
- v2 = Vector(0,0,0)
- print "Introduce dos vectores a continuacion: "
- v1.i = int(raw_input("i del vector 1? -> "))
- v1.j = int(raw_input("j del vector 1? -> "))
- v1.k = int(raw_input("k del vector 1? -> "))
- print imprime_vector(v1)
- v2.i = int(raw_input("i del vector 2? -> "))
- v2.j = int(raw_input("j del vector 2? -> "))
- v2.k = int(raw_input("k del vector 2? -> "))
- print imprime_vector(v2)
- s = suma(v1,v2)
- r1 = resta(v1,v2)
- r2 = resta(v2,v1)
- pp = producto_punto(v1,v2)
- pc1 = producto_cruz(v1,v2)
- pc2 = producto_cruz(v2,v1)
- print "La suma es " + str(s)
- print "La resta de v1-v2 es " + str(r1)
- print "La resta de v2-v1 es " + str(r2)
- print "El producto punto es " + str(pp)
- print "El producto cruz v1xv2 es " + str(pc1)
- print "El producto cruz v2xv1 es " + str(pc2)
- raw_input("\nPresione enter para continuar... ")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement