fork(5) download
  1. import math
  2.  
  3. class Vetor3D:
  4.  
  5. def __init__(self, x, y, z):
  6. self.x = x
  7. self.y = y
  8. self.z = z
  9.  
  10. def magnitude(self):
  11. return math.sqrt(self.x * self.x + self.y * self.y + self.z * self.z)
  12.  
  13. def produto_escalar(a, b):
  14. return a.x * b.x + a.y * b.y + a.z * b.z
  15.  
  16. def angulo(a, b):
  17. ta = a.magnitude()
  18. tb = b.magnitude()
  19. if ta == 0.0 or tb == 0.0:
  20. return 0.0
  21. return math.degrees(math.acos(produto_escalar(a, b) / ta / tb))
  22.  
  23. # Teste
  24. a = Vetor3D(1, 0, 0)
  25. b = Vetor3D(0, 1, 0)
  26. print(angulo(a, b))
  27.  
Success #stdin #stdout 0.01s 9992KB
stdin
Standard input is empty
stdout
90.0