I recently ran a simulation that I haven't looked at for a while.
It didn't run correctly: the physics was wrong. I can't be certain, but
I think it was doing the right thing last time I looked at it.
I'm trying to distill the program down to a small example that illustrates
the problem. The problem is rather mischievous (or I'm missing something
obvious) and attempts to write a small broken program haven't yet met with
success. Nonetheless ...
I discovered that if a replace the line
FMass.v = FMass.v + (Fext / FMass.m)*dt
FMass.v += (Fext / FMass.m)*dt
The behavior of the program changes. FMass is a sphere. FMass.v is a
visual vector, FMass.m is a scalar. Fext is a vector. Did I miss
something? Should I expect that "+=" will not increment a vector?
Interactively, I *can* correctly
increment a vector using "+=".
While I'm trying to track down the problem and write a small example, I
thought I'd check with the group for a sanity check.
From: Jonathan Brandmeyer <jbrandmeyer@ea...> - 2004-08-18 03:06:26
On Tue, 2004-08-17 at 15:11, gpajer@... wrote:
> Should I expect that "+=" will not increment a vector?
It should work (and does, as far as I can tell) partially because
visual.vector provides the __iadd__() "special member function". Worst
case, event if a visual.vector only provided __add__(), the interpreter
would synthesize the expression "x += y" as "x = x + y". Python floats
are manipulated in this way.
Consider this toy example:
>>> class fwrap(object):
... def __init__(self):
... self.x = 1.0
... def get(self):
... return self.x
... def __add__(self, other):
... return self.x + other
>>> f = fwrap()
>>> f + 1.0
>>> f += 1.0
Traceback (most recent call last):
File "<stdin>", line 1, in ?
AttributeError: 'float' object has no attribute 'get'