All problems
Angle Between Vectors
Problem
Return the angle between vectors a and b in degrees, using
theta = acos((a . b) / (||a||_2 * ||b||_2))
Clamp the cosine to [-1, 1] to avoid floating-point domain errors, and return 0.0 if either vector is zero.
Hint
Convert radians to degrees with math.degrees.
Test cases
case 1
in: [[1,0],[0,1]]
expected: 90
case 2
in: [[1,0],[1,0]]
expected: 0
case 3
in: [[1,0],[-1,0]]
expected: 180
case 4
in: [[1,1],[1,0]]
expected: 45
Starter codePython
def angle_between(a, b):
# Your code here
pass4 test cases · run your code against them in the editor