SHARE
TWEET

Untitled

jaredec18 Sep 15th, 2019 92 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. The required code in python 3.6
  2.  
  3.  
  4.  
  5. import math
  6. #calculates the dotproduct of two vectors
  7. def dotproduct(v1,v2):
  8.    sum = 0;
  9.    for i,j in zip(v1,v2):
  10.        sum = sum + (i*j)
  11.    return sum
  12.  
  13. #calculates magnitude of a vector  
  14. def magnitude(v):
  15.    return math.sqrt(dotproduct(v,v))
  16.  
  17. #returns angle between two vector in degrees
  18. def angleBetweenVector(v1,v2):
  19.    angleInRadians = math.acos(dotproduct(v1,v2)/   (magnitude(v1)*magnitude(v2)))
  20.    angleInDegrees = angleInRadians *180 / math.pi
  21.    return angleInDegrees
  22.  
  23. #take user inputs
  24. arr =    input("3D coordinates of obeserver: ")
  25. vo = [int(num) for num in arr.split()]
  26. arr =    input("3D coordinates of point 1 : ")
  27. v1 = [int(num) for num in arr.split()]
  28. arr =    input("3D coordinates of point 2 : ")
  29. v2 = [int(num) for num in arr.split()]
  30. #calculate displacement vector
  31. vo1 = [i-j for i,j in zip(v1,vo)]
  32. vo2 = [i-j for i,j in zip(v2,vo)]
  33. #output
  34. print("The magnitude of displacement vector(point 1 - observer) is : " + str(magnitude(vo1)))
  35. print("The magnitude of displacement vector(point 2 - observer) is : " + str(magnitude(vo2)))
  36. print("The dot product between vectors is : " + str(dotproduct(vo1,vo2)))
  37. print("The angle between vectors in degrees is : " + str(angleBetweenVector(vo1,vo2)))
  38.  
  39. for indentation refer screenshot attached
  40. https://media.cheggcdn.com/media%2Fd38%2Fd386a700-5ad6-4b73-8f05-656eb0d80d93%2Fphpicxyrw.png
  41.  
  42. https://media.cheggcdn.com/media%2F4b2%2F4b291b61-d360-4ab5-b240-f58a33c9a727%2Fphp5Xm9k8.png
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top