Re: [pygame] Pygame 2D vector

2011-07-23 Thread Greg Ewing
DR0ID wrote: get_length_sqrd just returns the length of a vector which does not depend on the quadrant. Using atan2 might be simpler The get_angle() method *does* use atan2. The length check seems to be just to avoid an exception if the vector happens to be (0, 0). -- Greg

Re: [pygame] Pygame 2D vector

2011-07-23 Thread Greg Ewing
sam.hack...@sent.com 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: [pygame] Pygame 2D vector

2011-07-23 Thread DR0ID
On 23.07.2011 14:23, sam.hack...@sent.com wrote: Well, when I type "-1**2" into Python, it returns -1. If I run "1**2 + -1**2" it returns 0. So, is there a bug in Python then? Running 2.6.6 on Ubuntu 10.10. Removing the if statement from get_angle fixed the angle problem for me, because of this

Re: [pygame] Pygame 2D vector

2011-07-23 Thread DR0ID
On 23.07.2011 14:26, sam.hack...@sent.com wrote: Ah, I see the problem, it's doing -(1**2), you need to put "(-1)**2". And, that's not a problem for the vector class, it's only because I modified my copy a little. OK, nevermind then. On Sat, 23 Jul 2011 13:23 +0100, sam.hack...@sent.com wrote:

Re: [pygame] Pygame 2D vector

2011-07-23 Thread sam . hacking
Ah, I see the problem, it's doing -(1**2), you need to put "(-1)**2". And, that's not a problem for the vector class, it's only because I modified my copy a little. OK, nevermind then. On Sat, 23 Jul 2011 13:23 +0100, sam.hack...@sent.com wrote: Well, when I type "-1**2" into Python, it returns -

Re: [pygame] Pygame 2D vector

2011-07-23 Thread sam . hacking
Well, when I type "-1**2" into Python, it returns -1. If I run "1**2 + -1**2" it returns 0. So, is there a bug in Python then? Running 2.6.6 on Ubuntu 10.10. Removing the if statement from get_angle fixed the angle problem for me, because of this. On Sat, 23 Jul 2011 13:56 +0200, "DR0ID" wrote:

Re: [pygame] Pygame 2D vector

2011-07-23 Thread DR0ID
On 23.07.2011 13:03, sam.hack...@sent.com wrote: On the 2D vector page, http://pygame.org/wiki/2DVectorClass 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*

[pygame] Pygame 2D vector

2011-07-23 Thread sam . hacking
On the 2D vector page, http://pygame.org/wiki/2DVectorClass 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, and so the angle is returned