0

I'm working with python 3.4 in pygame but I get a syntax error because of the second bracket in the function definition How can I fix this?

def addVectors((angle1, length1), (angle2, length2)):
    x  = math.sin(angle1) * length1 + math.sin(angle2) * length2
    y  = math.cos(angle1) * length1 + math.cos(angle2) * length2
    length = math.hypot(x, y)
    angle = 0.5 * math.pi - math.atan2(y, x)
    return (angle, length)
numbermaniac
  • 788
  • 1
  • 13
  • 28
A_S
  • 3
  • 1
  • 1
  • 2

1 Answers1

1

If your function is being passed in 2 tuples, you should extract the individual values from the tuples like so:

def addVectors(vector1, vector2):
    angle1, length1 = vector1
    angle2, length2 = vector2
    x  = math.sin(angle1) * length1 + math.sin(angle2) * length2
    y  = math.cos(angle1) * length1 + math.cos(angle2) * length2
    length = math.hypot(x, y)
    angle = 0.5 * math.pi - math.atan2(y, x)
    return (angle, length)
Irfan434
  • 1,463
  • 14
  • 19