[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] Pygame 2D vector
sam.hacking@xxxxxxxx wrote:
It has a get_angle() function, the first line of this checks if
length_sqrd() == 0, and then returns the angle as 0. This seems wrong to
me, if the vector is (1,-1), then length_sqrd (1**2 + -1**2) returns 0,
You're fooling yourself with operator precedence. If you're
typing that into the interactive interpreter, you need to
write it as
1**2 + (-1)**2
which has the value 2.
The code given for get_length_sqrd() is
return self.x**2 + self.y**2
which won't suffer from that problem.
--
Greg