0

I'm trying to make two lines across a circle, like an X. Since it's an X, to find the (x,y) I just multiplied sqrt(2)/2 by the radius and then added or subtracted it from the (x,y) origin depending on what corner of the circle it was in. However I keep getting a TypeError 'The error was: 2nd arg can't be coerced to int' This is what I have:

#starting/ending points of the line
a1 = z - ((sqrt(2) / 2)*(r1))
b1 = w - ((sqrt(2) / 2)*(r1))
a2 = z + ((sqrt(2) / 2)*(r1))
b2 = w + ((sqrt(2) / 2)*(r1))
c1 = z - ((sqrt(2) / 2)*(r1))
d1 = w + ((sqrt(2) / 2)*(r1))
c2 = z + ((sqrt(2) / 2)*(r1))
d2 = w - ((sqrt(2) / 2)*(r1))
pic.addLine(black, a1, b1, a2, b2)
pic.addLine(black, c1, d1, c2, d2)

...where z is the x origin, w is the y origin, and r1 is the radius. What am I doing wrong here? This what I'm getting :

enter image description here

2
  • 1
    Have you tried turning the a1, b1, a2, b2, etc. arguments to integer yet? int(a1), int(b1), int(a2), int(b2)? Commented Nov 16, 2013 at 18:06
  • What gets displayed if you do print type(a1) right before you call pic.addLine? Commented Nov 16, 2013 at 18:15

1 Answer 1

2

By using sqrt() you end up with floating point values, but the method you are calling wants integers only. Call int() on the values before passing them to pic.addLine():

pic.addLine(black, int(a1), int(b1), int(a2), int(b2))
pic.addLine(black, int(c1), int(d1), int(c2), int(d2))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.